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) {...@@ -156,6 +156,35 @@ pub const NullTerminatedString = enum(u32) {
156 _ = ctx;156 _ = ctx;
157 return @enumToInt(a) < @enumToInt(b);157 return @enumToInt(a) < @enumToInt(b);
158 }158 }
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 }
159};188};
160189
161/// An index into `string_bytes` which might be `none`.190/// An index into `string_bytes` which might be `none`.
...@@ -5252,10 +5281,9 @@ pub fn getOrPutString(...@@ -5252,10 +5281,9 @@ pub fn getOrPutString(
5252 gpa: Allocator,5281 gpa: Allocator,
5253 s: []const u8,5282 s: []const u8,
5254) Allocator.Error!NullTerminatedString {5283) Allocator.Error!NullTerminatedString {
5255 const string_bytes = &ip.string_bytes;5284 try ip.string_bytes.ensureUnusedCapacity(gpa, s.len + 1);
5256 try string_bytes.ensureUnusedCapacity(gpa, s.len + 1);5285 ip.string_bytes.appendSliceAssumeCapacity(s);
5257 string_bytes.appendSliceAssumeCapacity(s);5286 ip.string_bytes.appendAssumeCapacity(0);
5258 string_bytes.appendAssumeCapacity(0);
5259 return ip.getOrPutTrailingString(gpa, s.len + 1);5287 return ip.getOrPutTrailingString(gpa, s.len + 1);
5260}5288}
52615289
...@@ -5265,10 +5293,12 @@ pub fn getOrPutStringFmt(...@@ -5265,10 +5293,12 @@ pub fn getOrPutStringFmt(
5265 comptime format: []const u8,5293 comptime format: []const u8,
5266 args: anytype,5294 args: anytype,
5267) Allocator.Error!NullTerminatedString {5295) Allocator.Error!NullTerminatedString {
5268 const start = ip.string_bytes.items.len;5296 // ensure that references to string_bytes in args do not get invalidated
5269 try ip.string_bytes.writer(gpa).print(format, args);5297 const len = std.fmt.count(format, args) + 1;
5270 try ip.string_bytes.append(gpa, 0);5298 try ip.string_bytes.ensureUnusedCapacity(gpa, len);
5271 return ip.getOrPutTrailingString(gpa, ip.string_bytes.items.len - start);5299 ip.string_bytes.writer(undefined).print(format, args) catch unreachable;
5300 ip.string_bytes.appendAssumeCapacity(0);
5301 return ip.getOrPutTrailingString(gpa, len);
5272}5302}
52735303
5274pub fn getOrPutStringOpt(5304pub fn getOrPutStringOpt(
src/Module.zig+46-76
...@@ -270,11 +270,7 @@ pub const GlobalEmitH = struct {...@@ -270,11 +270,7 @@ pub const GlobalEmitH = struct {
270pub const ErrorInt = u32;270pub const ErrorInt = u32;
271271
272pub const Export = struct {272pub const Export = struct {
273 name: InternPool.NullTerminatedString,273 opts: Options,
274 linkage: std.builtin.GlobalLinkage,
275 section: InternPool.OptionalNullTerminatedString,
276 visibility: std.builtin.SymbolVisibility,
277
278 src: LazySrcLoc,274 src: LazySrcLoc,
279 /// The Decl that performs the export. Note that this is *not* the Decl being exported.275 /// The Decl that performs the export. Note that this is *not* the Decl being exported.
280 owner_decl: Decl.Index,276 owner_decl: Decl.Index,
...@@ -292,6 +288,13 @@ pub const Export = struct {...@@ -292,6 +288,13 @@ pub const Export = struct {
292 complete,288 complete,
293 },289 },
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
295 pub fn getSrcLoc(exp: Export, mod: *Module) SrcLoc {298 pub fn getSrcLoc(exp: Export, mod: *Module) SrcLoc {
296 const src_decl = mod.declPtr(exp.src_decl);299 const src_decl = mod.declPtr(exp.src_decl);
297 return .{300 return .{
...@@ -691,16 +694,15 @@ pub const Decl = struct {...@@ -691,16 +694,15 @@ pub const Decl = struct {
691 }694 }
692695
693 pub fn renderFullyQualifiedName(decl: Decl, mod: *Module, writer: anytype) !void {696 pub fn renderFullyQualifiedName(decl: Decl, mod: *Module, writer: anytype) !void {
694 const unqualified_name = mod.intern_pool.stringToSlice(decl.name);
695 if (decl.name_fully_qualified) {697 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);
697 }701 }
698 return mod.namespacePtr(decl.src_namespace).renderFullyQualifiedName(mod, unqualified_name, writer);
699 }702 }
700703
701 pub fn renderFullyQualifiedDebugName(decl: Decl, mod: *Module, writer: anytype) !void {704 pub fn renderFullyQualifiedDebugName(decl: Decl, mod: *Module, writer: anytype) !void {
702 const unqualified_name = mod.intern_pool.stringToSlice(decl.name);705 return mod.namespacePtr(decl.src_namespace).renderFullyQualifiedDebugName(mod, decl.name, writer);
703 return mod.namespacePtr(decl.src_namespace).renderFullyQualifiedDebugName(mod, unqualified_name, writer);
704 }706 }
705707
706 pub fn getFullyQualifiedName(decl: Decl, mod: *Module) !InternPool.NullTerminatedString {708 pub fn getFullyQualifiedName(decl: Decl, mod: *Module) !InternPool.NullTerminatedString {
...@@ -712,8 +714,7 @@ pub const Decl = struct {...@@ -712,8 +714,7 @@ pub const Decl = struct {
712 var ns: Namespace.Index = decl.src_namespace;714 var ns: Namespace.Index = decl.src_namespace;
713 while (true) {715 while (true) {
714 const namespace = mod.namespacePtr(ns);716 const namespace = mod.namespacePtr(ns);
715 const ns_decl_index = namespace.getDeclIndex(mod);717 const ns_decl = mod.declPtr(namespace.getDeclIndex(mod));
716 const ns_decl = mod.declPtr(ns_decl_index);
717 count += ip.stringToSlice(ns_decl.name).len + 1;718 count += ip.stringToSlice(ns_decl.name).len + 1;
718 ns = namespace.parent.unwrap() orelse {719 ns = namespace.parent.unwrap() orelse {
719 count += namespace.file_scope.sub_file_path.len;720 count += namespace.file_scope.sub_file_path.len;
...@@ -1722,44 +1723,34 @@ pub const Namespace = struct {...@@ -1722,44 +1723,34 @@ pub const Namespace = struct {
1722 pub fn renderFullyQualifiedName(1723 pub fn renderFullyQualifiedName(
1723 ns: Namespace,1724 ns: Namespace,
1724 mod: *Module,1725 mod: *Module,
1725 name: []const u8,1726 name: InternPool.NullTerminatedString,
1726 writer: anytype,1727 writer: anytype,
1727 ) @TypeOf(writer).Error!void {1728 ) @TypeOf(writer).Error!void {
1728 if (ns.parent.unwrap()) |parent| {1729 if (ns.parent.unwrap()) |parent| {
1729 const decl_index = ns.getDeclIndex(mod);1730 const decl = mod.declPtr(ns.getDeclIndex(mod));
1730 const decl = mod.declPtr(decl_index);1731 try mod.namespacePtr(parent).renderFullyQualifiedName(mod, decl.name, writer);
1731 const decl_name = mod.intern_pool.stringToSlice(decl.name);
1732 try mod.namespacePtr(parent).renderFullyQualifiedName(mod, decl_name, writer);
1733 } else {1732 } else {
1734 try ns.file_scope.renderFullyQualifiedName(writer);1733 try ns.file_scope.renderFullyQualifiedName(writer);
1735 }1734 }
1736 if (name.len != 0) {1735 if (name != .empty) try writer.print(".{}", .{name.fmt(&mod.intern_pool)});
1737 try writer.writeAll(".");
1738 try writer.writeAll(name);
1739 }
1740 }1736 }
17411737
1742 /// This renders e.g. "std/fs.zig:Dir.OpenOptions"1738 /// This renders e.g. "std/fs.zig:Dir.OpenOptions"
1743 pub fn renderFullyQualifiedDebugName(1739 pub fn renderFullyQualifiedDebugName(
1744 ns: Namespace,1740 ns: Namespace,
1745 mod: *Module,1741 mod: *Module,
1746 name: []const u8,1742 name: InternPool.NullTerminatedString,
1747 writer: anytype,1743 writer: anytype,
1748 ) @TypeOf(writer).Error!void {1744 ) @TypeOf(writer).Error!void {
1749 var separator_char: u8 = '.';1745 const separator_char: u8 = if (ns.parent.unwrap()) |parent| sep: {
1750 if (ns.parent.unwrap()) |parent| {1746 const decl = mod.declPtr(ns.getDeclIndex(mod));
1751 const decl_index = ns.getDeclIndex(mod);1747 try mod.namespacePtr(parent).renderFullyQualifiedDebugName(mod, decl.name, writer);
1752 const decl = mod.declPtr(decl_index);1748 break :sep '.';
1753 const decl_name = mod.intern_pool.stringToSlice(decl.name);1749 } else sep: {
1754 try mod.namespacePtr(parent).renderFullyQualifiedDebugName(mod, decl_name, writer);
1755 } else {
1756 try ns.file_scope.renderFullyQualifiedDebugName(writer);1750 try ns.file_scope.renderFullyQualifiedDebugName(writer);
1757 separator_char = ':';1751 break :sep ':';
1758 }1752 };
1759 if (name.len != 0) {1753 if (name != .empty) try writer.print("{c}{}", .{ separator_char, name.fmt(&mod.intern_pool) });
1760 try writer.writeByte(separator_char);
1761 try writer.writeAll(name);
1762 }
1763 }1754 }
17641755
1765 pub fn getDeclIndex(ns: Namespace, mod: *Module) Decl.Index {1756 pub fn getDeclIndex(ns: Namespace, mod: *Module) Decl.Index {
...@@ -4185,10 +4176,10 @@ pub fn ensureFuncBodyAnalyzed(mod: *Module, func_index: Fn.Index) SemaError!void...@@ -4185,10 +4176,10 @@ pub fn ensureFuncBodyAnalyzed(mod: *Module, func_index: Fn.Index) SemaError!void
4185 defer liveness.deinit(gpa);4176 defer liveness.deinit(gpa);
41864177
4187 if (dump_air) {4178 if (dump_air) {
4188 const fqn = mod.intern_pool.stringToSlice(try decl.getFullyQualifiedName(mod));4179 const fqn = try decl.getFullyQualifiedName(mod);
4189 std.debug.print("# Begin Function AIR: {s}:\n", .{fqn});4180 std.debug.print("# Begin Function AIR: {}:\n", .{fqn.fmt(&mod.intern_pool)});
4190 @import("print_air.zig").dump(mod, air, liveness);4181 @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)});
4192 }4183 }
41934184
4194 if (std.debug.runtime_safety) {4185 if (std.debug.runtime_safety) {
...@@ -4620,10 +4611,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {...@@ -4620,10 +4611,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
4620 return sema.fail(&block_scope, export_src, "export of inline function", .{});4611 return sema.fail(&block_scope, export_src, "export of inline function", .{});
4621 }4612 }
4622 // The scope needs to have the decl in it.4613 // The scope needs to have the decl in it.
4623 const options: std.builtin.ExportOptions = .{4614 try sema.analyzeExport(&block_scope, export_src, .{ .name = decl.name }, decl_index);
4624 .name = mod.intern_pool.stringToSlice(decl.name),
4625 };
4626 try sema.analyzeExport(&block_scope, export_src, options, decl_index);
4627 }4615 }
4628 return type_changed or is_inline != prev_is_inline;4616 return type_changed or is_inline != prev_is_inline;
4629 }4617 }
...@@ -4720,10 +4708,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {...@@ -4720,10 +4708,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
4720 if (decl.is_exported) {4708 if (decl.is_exported) {
4721 const export_src: LazySrcLoc = .{ .token_offset = @boolToInt(decl.is_pub) };4709 const export_src: LazySrcLoc = .{ .token_offset = @boolToInt(decl.is_pub) };
4722 // The scope needs to have the decl in it.4710 // The scope needs to have the decl in it.
4723 const options: std.builtin.ExportOptions = .{4711 try sema.analyzeExport(&block_scope, export_src, .{ .name = decl.name }, decl_index);
4724 .name = mod.intern_pool.stringToSlice(decl.name),
4725 };
4726 try sema.analyzeExport(&block_scope, export_src, options, decl_index);
4727 }4712 }
47284713
4729 return type_changed;4714 return type_changed;
...@@ -5222,12 +5207,9 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err...@@ -5222,12 +5207,9 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err
5222 .parent_decl_node = decl.src_node,5207 .parent_decl_node = decl.src_node,
5223 .lazy = .{ .token_offset = 1 },5208 .lazy = .{ .token_offset = 1 },
5224 };5209 };
5225 const msg = try ErrorMsg.create(5210 const msg = try ErrorMsg.create(gpa, src_loc, "duplicate test name: {}", .{
5226 gpa,5211 decl_name.fmt(&mod.intern_pool),
5227 src_loc,5212 });
5228 "duplicate test name: {s}",
5229 .{ip.stringToSlice(decl_name)},
5230 );
5231 errdefer msg.destroy(gpa);5213 errdefer msg.destroy(gpa);
5232 try mod.failed_decls.putNoClobber(gpa, decl_index, msg);5214 try mod.failed_decls.putNoClobber(gpa, decl_index, msg);
5233 const other_src_loc = SrcLoc{5215 const other_src_loc = SrcLoc{
...@@ -5417,16 +5399,16 @@ fn deleteDeclExports(mod: *Module, decl_index: Decl.Index) Allocator.Error!void...@@ -5417,16 +5399,16 @@ fn deleteDeclExports(mod: *Module, decl_index: Decl.Index) Allocator.Error!void
5417 }5399 }
5418 }5400 }
5419 if (mod.comp.bin_file.cast(link.File.Elf)) |elf| {5401 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);
5421 }5403 }
5422 if (mod.comp.bin_file.cast(link.File.MachO)) |macho| {5404 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);
5424 }5406 }
5425 if (mod.comp.bin_file.cast(link.File.Wasm)) |wasm| {5407 if (mod.comp.bin_file.cast(link.File.Wasm)) |wasm| {
5426 wasm.deleteDeclExport(decl_index);5408 wasm.deleteDeclExport(decl_index);
5427 }5409 }
5428 if (mod.comp.bin_file.cast(link.File.Coff)) |coff| {5410 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);
5430 }5412 }
5431 if (mod.failed_exports.fetchSwapRemove(exp)) |failed_kv| {5413 if (mod.failed_exports.fetchSwapRemove(exp)) |failed_kv| {
5432 failed_kv.value.destroy(mod.gpa);5414 failed_kv.value.destroy(mod.gpa);
...@@ -5810,12 +5792,9 @@ pub fn createAnonymousDeclFromDecl(...@@ -5810,12 +5792,9 @@ pub fn createAnonymousDeclFromDecl(
5810) !Decl.Index {5792) !Decl.Index {
5811 const new_decl_index = try mod.allocateNewDecl(namespace, src_decl.src_node, src_scope);5793 const new_decl_index = try mod.allocateNewDecl(namespace, src_decl.src_node, src_scope);
5812 errdefer mod.destroyDecl(new_decl_index);5794 errdefer mod.destroyDecl(new_decl_index);
5813 const ip = &mod.intern_pool;5795 const name = try mod.intern_pool.getOrPutStringFmt(mod.gpa, "{}__anon_{d}", .{
5814 // This protects the getOrPutStringFmt from reallocating src decl name while reading it.5796 src_decl.name.fmt(&mod.intern_pool), @enumToInt(new_decl_index),
5815 try ip.string_bytes.ensureUnusedCapacity(mod.gpa, ip.stringToSlice(src_decl.name).len + 20);5797 });
5816 const name = ip.getOrPutStringFmt(mod.gpa, "{s}__anon_{d}", .{
5817 ip.stringToSlice(src_decl.name), @enumToInt(new_decl_index),
5818 }) catch unreachable;
5819 try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, namespace, tv, name);5798 try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, namespace, tv, name);
5820 return new_decl_index;5799 return new_decl_index;
5821}5800}
...@@ -6301,13 +6280,13 @@ pub fn processExports(mod: *Module) !void {...@@ -6301,13 +6280,13 @@ pub fn processExports(mod: *Module) !void {
6301 const exported_decl = entry.key_ptr.*;6280 const exported_decl = entry.key_ptr.*;
6302 const exports = entry.value_ptr.items;6281 const exports = entry.value_ptr.items;
6303 for (exports) |new_export| {6282 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);
6305 if (gop.found_existing) {6284 if (gop.found_existing) {
6306 new_export.status = .failed_retryable;6285 new_export.status = .failed_retryable;
6307 try mod.failed_exports.ensureUnusedCapacity(gpa, 1);6286 try mod.failed_exports.ensureUnusedCapacity(gpa, 1);
6308 const src_loc = new_export.getSrcLoc(mod);6287 const src_loc = new_export.getSrcLoc(mod);
6309 const msg = try ErrorMsg.create(gpa, src_loc, "exported symbol collision: {s}", .{6288 const msg = try ErrorMsg.create(gpa, src_loc, "exported symbol collision: {}", .{
6310 mod.intern_pool.stringToSlice(new_export.name),6289 new_export.opts.name.fmt(&mod.intern_pool),
6311 });6290 });
6312 errdefer msg.destroy(gpa);6291 errdefer msg.destroy(gpa);
6313 const other_export = gop.value_ptr.*;6292 const other_export = gop.value_ptr.*;
...@@ -6752,18 +6731,9 @@ pub fn errorUnionType(mod: *Module, error_set_ty: Type, payload_ty: Type) Alloca...@@ -6752,18 +6731,9 @@ pub fn errorUnionType(mod: *Module, error_set_ty: Type, payload_ty: Type) Alloca
6752 } })).toType();6731 } })).toType();
6753}6732}
67546733
6755pub fn singleErrorSetType(mod: *Module, name: []const u8) Allocator.Error!Type {6734pub fn singleErrorSetType(mod: *Module, name: InternPool.NullTerminatedString) Allocator.Error!Type {
6756 const gpa = mod.gpa;6735 const names: *const [1]InternPool.NullTerminatedString = &name;
6757 const ip = &mod.intern_pool;6736 return (try mod.intern_pool.get(mod.gpa, .{ .error_set_type = .{ .names = names } })).toType();
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();
6767}6737}
67686738
6769/// Sorts `names` in place.6739/// Sorts `names` in place.
src/Sema.zig+386-416
...@@ -309,17 +309,17 @@ pub const Block = struct {...@@ -309,17 +309,17 @@ pub const Block = struct {
309 src_loc.lazy = .{ .node_offset_fn_type_ret_ty = 0 };309 src_loc.lazy = .{ .node_offset_fn_type_ret_ty = 0 };
310 break :blk src_loc;310 break :blk src_loc;
311 } else blk: {311 } else blk: {
312 const src_decl = sema.mod.declPtr(rt.block.src_decl);312 const src_decl = mod.declPtr(rt.block.src_decl);
313 break :blk rt.func_src.toSrcLoc(src_decl, mod);313 break :blk rt.func_src.toSrcLoc(src_decl, mod);
314 };314 };
315 if (rt.return_ty.isGenericPoison()) {315 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", .{});
317 }317 }
318 try sema.mod.errNoteNonLazy(318 try mod.errNoteNonLazy(
319 src_loc,319 src_loc,
320 parent,320 parent,
321 prefix ++ "the function returns a comptime-only type '{}'",321 prefix ++ "the function returns a comptime-only type '{}'",
322 .{rt.return_ty.fmt(sema.mod)},322 .{rt.return_ty.fmt(mod)},
323 );323 );
324 try sema.explainWhyTypeIsComptime(parent, src_loc, rt.return_ty);324 try sema.explainWhyTypeIsComptime(parent, src_loc, rt.return_ty);
325 },325 },
...@@ -2825,7 +2825,6 @@ fn createAnonymousDeclTypeNamed(...@@ -2825,7 +2825,6 @@ fn createAnonymousDeclTypeNamed(
2825) !Decl.Index {2825) !Decl.Index {
2826 const mod = sema.mod;2826 const mod = sema.mod;
2827 const gpa = sema.gpa;2827 const gpa = sema.gpa;
2828 const ip = &mod.intern_pool;
2829 const namespace = block.namespace;2828 const namespace = block.namespace;
2830 const src_scope = block.wip_capture_scope;2829 const src_scope = block.wip_capture_scope;
2831 const src_decl = mod.declPtr(block.src_decl);2830 const src_decl = mod.declPtr(block.src_decl);
...@@ -2842,12 +2841,8 @@ fn createAnonymousDeclTypeNamed(...@@ -2842,12 +2841,8 @@ fn createAnonymousDeclTypeNamed(
2842 // This name is also used as the key in the parent namespace so it cannot be2841 // This name is also used as the key in the parent namespace so it cannot be
2843 // renamed.2842 // renamed.
28442843
2845 // This ensureUnusedCapacity protects against the src_decl slice from being2844 const name = mod.intern_pool.getOrPutStringFmt(gpa, "{}__{s}_{d}", .{
2846 // reallocated during the call to `getOrPutStringFmt`.2845 src_decl.name.fmt(&mod.intern_pool), anon_prefix, @enumToInt(new_decl_index),
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),
2851 }) catch unreachable;2846 }) catch unreachable;
2852 try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, namespace, typed_value, name);2847 try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, namespace, typed_value, name);
2853 return new_decl_index;2848 return new_decl_index;
...@@ -2863,8 +2858,9 @@ fn createAnonymousDeclTypeNamed(...@@ -2863,8 +2858,9 @@ fn createAnonymousDeclTypeNamed(
28632858
2864 var buf = std.ArrayList(u8).init(gpa);2859 var buf = std.ArrayList(u8).init(gpa);
2865 defer buf.deinit();2860 defer buf.deinit();
2866 try buf.appendSlice(ip.stringToSlice(mod.declPtr(block.src_decl).name));2861
2867 try buf.appendSlice("(");2862 const writer = buf.writer();
2863 try writer.print("{}(", .{mod.declPtr(block.src_decl).name.fmt(&mod.intern_pool)});
28682864
2869 var arg_i: usize = 0;2865 var arg_i: usize = 0;
2870 for (fn_info.param_body) |zir_inst| switch (zir_tags[zir_inst]) {2866 for (fn_info.param_body) |zir_inst| switch (zir_tags[zir_inst]) {
...@@ -2878,8 +2874,8 @@ fn createAnonymousDeclTypeNamed(...@@ -2878,8 +2874,8 @@ fn createAnonymousDeclTypeNamed(
2878 const arg_val = sema.resolveConstMaybeUndefVal(block, .unneeded, arg, "") catch2874 const arg_val = sema.resolveConstMaybeUndefVal(block, .unneeded, arg, "") catch
2879 return sema.createAnonymousDeclTypeNamed(block, src, typed_value, .anon, anon_prefix, null);2875 return sema.createAnonymousDeclTypeNamed(block, src, typed_value, .anon, anon_prefix, null);
28802876
2881 if (arg_i != 0) try buf.appendSlice(",");2877 if (arg_i != 0) try writer.writeByte(',');
2882 try buf.writer().print("{}", .{arg_val.fmtValue(sema.typeOf(arg), sema.mod)});2878 try writer.print("{}", .{arg_val.fmtValue(sema.typeOf(arg), sema.mod)});
28832879
2884 arg_i += 1;2880 arg_i += 1;
2885 continue;2881 continue;
...@@ -2887,8 +2883,8 @@ fn createAnonymousDeclTypeNamed(...@@ -2887,8 +2883,8 @@ fn createAnonymousDeclTypeNamed(
2887 else => continue,2883 else => continue,
2888 };2884 };
28892885
2890 try buf.appendSlice(")");2886 try writer.writeByte(')');
2891 const name = try ip.getOrPutString(gpa, buf.items);2887 const name = try mod.intern_pool.getOrPutString(gpa, buf.items);
2892 try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, namespace, typed_value, name);2888 try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, namespace, typed_value, name);
2893 return new_decl_index;2889 return new_decl_index;
2894 },2890 },
...@@ -2901,17 +2897,9 @@ fn createAnonymousDeclTypeNamed(...@@ -2901,17 +2897,9 @@ fn createAnonymousDeclTypeNamed(
2901 .dbg_var_ptr, .dbg_var_val => {2897 .dbg_var_ptr, .dbg_var_val => {
2902 if (zir_data[i].str_op.operand != ref) continue;2898 if (zir_data[i].str_op.operand != ref) continue;
29032899
2904 // This ensureUnusedCapacity protects against the src_decl2900 const name = try mod.intern_pool.getOrPutStringFmt(gpa, "{}.{s}", .{
2905 // slice from being reallocated during the call to2901 src_decl.name.fmt(&mod.intern_pool), zir_data[i].str_op.getStr(sema.code),
2906 // `getOrPutStringFmt`.2902 });
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;
29152903
2916 try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, namespace, typed_value, name);2904 try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, namespace, typed_value, name);
2917 return new_decl_index;2905 return new_decl_index;
...@@ -4538,8 +4526,8 @@ fn validateStructInit(...@@ -4538,8 +4526,8 @@ fn validateStructInit(
4538 continue;4526 continue;
4539 }4527 }
4540 const field_name = struct_ty.structFieldName(i, mod);4528 const field_name = struct_ty.structFieldName(i, mod);
4541 const template = "missing struct field: {s}";4529 const template = "missing struct field: {}";
4542 const args = .{ip.stringToSlice(field_name)};4530 const args = .{field_name.fmt(ip)};
4543 if (root_msg) |msg| {4531 if (root_msg) |msg| {
4544 try sema.errNote(block, init_src, msg, template, args);4532 try sema.errNote(block, init_src, msg, template, args);
4545 } else {4533 } else {
...@@ -4560,12 +4548,12 @@ fn validateStructInit(...@@ -4560,12 +4548,12 @@ fn validateStructInit(
45604548
4561 if (root_msg) |msg| {4549 if (root_msg) |msg| {
4562 if (mod.typeToStruct(struct_ty)) |struct_obj| {4550 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);
4564 try mod.errNoteNonLazy(4552 try mod.errNoteNonLazy(
4565 struct_obj.srcLoc(mod),4553 struct_obj.srcLoc(mod),
4566 msg,4554 msg,
4567 "struct '{s}' declared here",4555 "struct '{}' declared here",
4568 .{fqn},4556 .{fqn.fmt(ip)},
4569 );4557 );
4570 }4558 }
4571 root_msg = null;4559 root_msg = null;
...@@ -4682,8 +4670,8 @@ fn validateStructInit(...@@ -4682,8 +4670,8 @@ fn validateStructInit(
4682 continue;4670 continue;
4683 }4671 }
4684 const field_name = struct_ty.structFieldName(i, mod);4672 const field_name = struct_ty.structFieldName(i, mod);
4685 const template = "missing struct field: {s}";4673 const template = "missing struct field: {}";
4686 const args = .{ip.stringToSlice(field_name)};4674 const args = .{field_name.fmt(ip)};
4687 if (root_msg) |msg| {4675 if (root_msg) |msg| {
4688 try sema.errNote(block, init_src, msg, template, args);4676 try sema.errNote(block, init_src, msg, template, args);
4689 } else {4677 } else {
...@@ -4696,12 +4684,12 @@ fn validateStructInit(...@@ -4696,12 +4684,12 @@ fn validateStructInit(
46964684
4697 if (root_msg) |msg| {4685 if (root_msg) |msg| {
4698 if (mod.typeToStruct(struct_ty)) |struct_obj| {4686 if (mod.typeToStruct(struct_ty)) |struct_obj| {
4699 const fqn = ip.stringToSlice(try struct_obj.getFullyQualifiedName(mod));4687 const fqn = try struct_obj.getFullyQualifiedName(mod);
4700 try sema.mod.errNoteNonLazy(4688 try mod.errNoteNonLazy(
4701 struct_obj.srcLoc(mod),4689 struct_obj.srcLoc(mod),
4702 msg,4690 msg,
4703 "struct '{s}' declared here",4691 "struct '{}' declared here",
4704 .{fqn},4692 .{fqn.fmt(ip)},
4705 );4693 );
4706 }4694 }
4707 root_msg = null;4695 root_msg = null;
...@@ -4942,11 +4930,11 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr...@@ -4942,11 +4930,11 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
4942 const operand_ty = sema.typeOf(operand);4930 const operand_ty = sema.typeOf(operand);
49434931
4944 if (operand_ty.zigTypeTag(mod) != .Pointer) {4932 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)});
4946 } else switch (operand_ty.ptrSize(mod)) {4934 } else switch (operand_ty.ptrSize(mod)) {
4947 .One, .C => {},4935 .One, .C => {},
4948 .Many => return sema.fail(block, src, "index syntax required for unknown-length pointer 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)}),
4949 .Slice => return sema.fail(block, src, "index syntax required for slice type '{}'", .{operand_ty.fmt(sema.mod)}),4937 .Slice => return sema.fail(block, src, "index syntax required for slice type '{}'", .{operand_ty.fmt(mod)}),
4950 }4938 }
49514939
4952 if ((try sema.typeHasOnePossibleValue(operand_ty.childType(mod))) != null) {4940 if ((try sema.typeHasOnePossibleValue(operand_ty.childType(mod))) != null) {
...@@ -4965,11 +4953,11 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr...@@ -4965,11 +4953,11 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
4965 block,4953 block,
4966 src,4954 src,
4967 "values of type '{}' must be comptime-known, but operand value is runtime-known",4955 "values of type '{}' must be comptime-known, but operand value is runtime-known",
4968 .{elem_ty.fmt(sema.mod)},4956 .{elem_ty.fmt(mod)},
4969 );4957 );
4970 errdefer msg.destroy(sema.gpa);4958 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);
4973 try sema.explainWhyTypeIsComptime(msg, src.toSrcLoc(src_decl, mod), elem_ty);4961 try sema.explainWhyTypeIsComptime(msg, src.toSrcLoc(src_decl, mod), elem_ty);
4974 break :msg msg;4962 break :msg msg;
4975 };4963 };
...@@ -4982,7 +4970,7 @@ fn failWithBadMemberAccess(...@@ -4982,7 +4970,7 @@ fn failWithBadMemberAccess(
4982 block: *Block,4970 block: *Block,
4983 agg_ty: Type,4971 agg_ty: Type,
4984 field_src: LazySrcLoc,4972 field_src: LazySrcLoc,
4985 field_name_nts: InternPool.NullTerminatedString,4973 field_name: InternPool.NullTerminatedString,
4986) CompileError {4974) CompileError {
4987 const mod = sema.mod;4975 const mod = sema.mod;
4988 const kw_name = switch (agg_ty.zigTypeTag(mod)) {4976 const kw_name = switch (agg_ty.zigTypeTag(mod)) {
...@@ -4992,15 +4980,14 @@ fn failWithBadMemberAccess(...@@ -4992,15 +4980,14 @@ fn failWithBadMemberAccess(
4992 .Enum => "enum",4980 .Enum => "enum",
4993 else => unreachable,4981 else => unreachable,
4994 };4982 };
4995 const field_name = mod.intern_pool.stringToSlice(field_name_nts);4983 if (agg_ty.getOwnerDeclOrNull(mod)) |some| if (mod.declIsRoot(some)) {
4996 if (agg_ty.getOwnerDeclOrNull(mod)) |some| if (sema.mod.declIsRoot(some)) {4984 return sema.fail(block, field_src, "root struct of file '{}' has no member named '{}'", .{
4997 return sema.fail(block, field_src, "root struct of file '{}' has no member named '{s}'", .{4985 agg_ty.fmt(mod), field_name.fmt(&mod.intern_pool),
4998 agg_ty.fmt(sema.mod), field_name,
4999 });4986 });
5000 };4987 };
5001 const msg = msg: {4988 const msg = msg: {
5002 const msg = try sema.errMsg(block, field_src, "{s} '{}' has no member named '{s}'", .{4989 const msg = try sema.errMsg(block, field_src, "{s} '{}' has no member named '{}'", .{
5003 kw_name, agg_ty.fmt(sema.mod), field_name,4990 kw_name, agg_ty.fmt(mod), field_name.fmt(&mod.intern_pool),
5004 });4991 });
5005 errdefer msg.destroy(sema.gpa);4992 errdefer msg.destroy(sema.gpa);
5006 try sema.addDeclaredHereNote(msg, agg_ty);4993 try sema.addDeclaredHereNote(msg, agg_ty);
...@@ -5018,16 +5005,15 @@ fn failWithBadStructFieldAccess(...@@ -5018,16 +5005,15 @@ fn failWithBadStructFieldAccess(
5018) CompileError {5005) CompileError {
5019 const mod = sema.mod;5006 const mod = sema.mod;
5020 const gpa = sema.gpa;5007 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
5025 const msg = msg: {5011 const msg = msg: {
5026 const msg = try sema.errMsg(5012 const msg = try sema.errMsg(
5027 block,5013 block,
5028 field_src,5014 field_src,
5029 "no field named '{s}' in struct '{s}'",5015 "no field named '{}' in struct '{}'",
5030 .{ ip.stringToSlice(field_name), fqn },5016 .{ field_name.fmt(&mod.intern_pool), fqn.fmt(&mod.intern_pool) },
5031 );5017 );
5032 errdefer msg.destroy(gpa);5018 errdefer msg.destroy(gpa);
5033 try mod.errNoteNonLazy(struct_obj.srcLoc(mod), msg, "struct declared here", .{});5019 try mod.errNoteNonLazy(struct_obj.srcLoc(mod), msg, "struct declared here", .{});
...@@ -5045,16 +5031,15 @@ fn failWithBadUnionFieldAccess(...@@ -5045,16 +5031,15 @@ fn failWithBadUnionFieldAccess(
5045) CompileError {5031) CompileError {
5046 const mod = sema.mod;5032 const mod = sema.mod;
5047 const gpa = sema.gpa;5033 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
5052 const msg = msg: {5037 const msg = msg: {
5053 const msg = try sema.errMsg(5038 const msg = try sema.errMsg(
5054 block,5039 block,
5055 field_src,5040 field_src,
5056 "no field named '{s}' in union '{s}'",5041 "no field named '{}' in union '{}'",
5057 .{ ip.stringToSlice(field_name), fqn },5042 .{ field_name.fmt(&mod.intern_pool), fqn.fmt(&mod.intern_pool) },
5058 );5043 );
5059 errdefer msg.destroy(gpa);5044 errdefer msg.destroy(gpa);
5060 try mod.errNoteNonLazy(union_obj.srcLoc(mod), msg, "union declared here", .{});5045 try mod.errNoteNonLazy(union_obj.srcLoc(mod), msg, "union declared here", .{});
...@@ -5334,7 +5319,9 @@ fn zirCompileLog(...@@ -5334,7 +5319,9 @@ fn zirCompileLog(
5334 sema: *Sema,5319 sema: *Sema,
5335 extended: Zir.Inst.Extended.InstData,5320 extended: Zir.Inst.Extended.InstData,
5336) CompileError!Air.Inst.Ref {5321) 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);
5338 defer sema.mod.compile_log_text = managed.moveToUnmanaged();5325 defer sema.mod.compile_log_text = managed.moveToUnmanaged();
5339 const writer = managed.writer();5326 const writer = managed.writer();
53405327
...@@ -5349,16 +5336,16 @@ fn zirCompileLog(...@@ -5349,16 +5336,16 @@ fn zirCompileLog(
5349 const arg_ty = sema.typeOf(arg);5336 const arg_ty = sema.typeOf(arg);
5350 if (try sema.resolveMaybeUndefLazyVal(arg)) |val| {5337 if (try sema.resolveMaybeUndefLazyVal(arg)) |val| {
5351 try writer.print("@as({}, {})", .{5338 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),
5353 });5340 });
5354 } else {5341 } else {
5355 try writer.print("@as({}, [runtime value])", .{arg_ty.fmt(sema.mod)});5342 try writer.print("@as({}, [runtime value])", .{arg_ty.fmt(mod)});
5356 }5343 }
5357 }5344 }
5358 try writer.print("\n", .{});5345 try writer.print("\n", .{});
53595346
5360 const decl_index = if (sema.func) |some| some.owner_decl else sema.owner_decl_index;5347 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);
5362 if (!gop.found_existing) {5349 if (!gop.found_existing) {
5363 gop.value_ptr.* = src_node;5350 gop.value_ptr.* = src_node;
5364 }5351 }
...@@ -5509,7 +5496,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr...@@ -5509,7 +5496,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
5509 if (!mod.comp.bin_file.options.link_libc)5496 if (!mod.comp.bin_file.options.link_libc)
5510 try sema.errNote(&child_block, src, msg, "libc headers not available; compilation does not link against libc", .{});5497 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);
5513 if (!gop.found_existing) {5500 if (!gop.found_existing) {
5514 var errs = try std.ArrayListUnmanaged(Module.CImportError).initCapacity(sema.gpa, c_import_res.errors.len);5501 var errs = try std.ArrayListUnmanaged(Module.CImportError).initCapacity(sema.gpa, c_import_res.errors.len);
5515 errdefer {5502 errdefer {
...@@ -5869,13 +5856,13 @@ pub fn analyzeExport(...@@ -5869,13 +5856,13 @@ pub fn analyzeExport(
5869 sema: *Sema,5856 sema: *Sema,
5870 block: *Block,5857 block: *Block,
5871 src: LazySrcLoc,5858 src: LazySrcLoc,
5872 borrowed_options: std.builtin.ExportOptions,5859 options: Module.Export.Options,
5873 exported_decl_index: Decl.Index,5860 exported_decl_index: Decl.Index,
5874) !void {5861) !void {
5875 const Export = Module.Export;5862 const Export = Module.Export;
5876 const mod = sema.mod;5863 const mod = sema.mod;
58775864
5878 if (borrowed_options.linkage == .Internal) {5865 if (options.linkage == .Internal) {
5879 return;5866 return;
5880 }5867 }
58815868
...@@ -5884,10 +5871,10 @@ pub fn analyzeExport(...@@ -5884,10 +5871,10 @@ pub fn analyzeExport(
58845871
5885 if (!try sema.validateExternType(exported_decl.ty, .other)) {5872 if (!try sema.validateExternType(exported_decl.ty, .other)) {
5886 const msg = msg: {5873 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)});
5888 errdefer msg.destroy(sema.gpa);5875 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);
5891 try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl, mod), exported_decl.ty, .other);5878 try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl, mod), exported_decl.ty, .other);
58925879
5893 try sema.addDeclaredHereNote(msg, exported_decl.ty);5880 try sema.addDeclaredHereNote(msg, exported_decl.ty);
...@@ -5913,14 +5900,8 @@ pub fn analyzeExport(...@@ -5913,14 +5900,8 @@ pub fn analyzeExport(
5913 const new_export = try gpa.create(Export);5900 const new_export = try gpa.create(Export);
5914 errdefer gpa.destroy(new_export);5901 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
5919 new_export.* = .{5903 new_export.* = .{
5920 .name = symbol_name,5904 .opts = options,
5921 .linkage = borrowed_options.linkage,
5922 .section = section,
5923 .visibility = borrowed_options.visibility,
5924 .src = src,5905 .src = src,
5925 .owner_decl = sema.owner_decl_index,5906 .owner_decl = sema.owner_decl_index,
5926 .src_decl = block.src_decl,5907 .src_decl = block.src_decl,
...@@ -6198,7 +6179,7 @@ fn lookupInNamespace(...@@ -6198,7 +6179,7 @@ fn lookupInNamespace(
61986179
6199 const namespace = mod.namespacePtr(namespace_index);6180 const namespace = mod.namespacePtr(namespace_index);
6200 const namespace_decl_index = namespace.getDeclIndex(mod);6181 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);
6202 if (namespace_decl.analysis == .file_failure) {6183 if (namespace_decl.analysis == .file_failure) {
6203 try mod.declareDeclDependency(sema.owner_decl_index, namespace_decl_index);6184 try mod.declareDeclDependency(sema.owner_decl_index, namespace_decl_index);
6204 return error.AnalysisFail;6185 return error.AnalysisFail;
...@@ -6531,7 +6512,7 @@ fn zirCall(...@@ -6531,7 +6512,7 @@ fn zirCall(
6531 // AstGen ensures that a call instruction is always preceded by a dbg_stmt instruction.6512 // AstGen ensures that a call instruction is always preceded by a dbg_stmt instruction.
6532 const call_dbg_node = inst - 1;6513 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 and6515 if (mod.backendSupportsFeature(.error_return_trace) and mod.comp.bin_file.options.error_return_tracing and
6535 !block.is_comptime and !block.is_typeof and (input_is_error or pop_error_return_trace))6516 !block.is_comptime and !block.is_typeof and (input_is_error or pop_error_return_trace))
6536 {6517 {
6537 const call_inst: Air.Inst.Ref = if (modifier == .always_tail) undefined else b: {6518 const call_inst: Air.Inst.Ref = if (modifier == .always_tail) undefined else b: {
...@@ -6599,7 +6580,7 @@ fn checkCallArgumentCount(...@@ -6599,7 +6580,7 @@ fn checkCallArgumentCount(
6599 {6580 {
6600 const msg = msg: {6581 const msg = msg: {
6601 const msg = try sema.errMsg(block, func_src, "cannot call optional type '{}'", .{6582 const msg = try sema.errMsg(block, func_src, "cannot call optional type '{}'", .{
6602 callee_ty.fmt(sema.mod),6583 callee_ty.fmt(mod),
6603 });6584 });
6604 errdefer msg.destroy(sema.gpa);6585 errdefer msg.destroy(sema.gpa);
6605 try sema.errNote(block, func_src, msg, "consider using '.?', 'orelse' or 'if'", .{});6586 try sema.errNote(block, func_src, msg, "consider using '.?', 'orelse' or 'if'", .{});
...@@ -6610,7 +6591,7 @@ fn checkCallArgumentCount(...@@ -6610,7 +6591,7 @@ fn checkCallArgumentCount(
6610 },6591 },
6611 else => {},6592 else => {},
6612 }6593 }
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)});
6614 };6595 };
66156596
6616 const func_ty_info = mod.typeToFunc(func_ty).?;6597 const func_ty_info = mod.typeToFunc(func_ty).?;
...@@ -6640,7 +6621,7 @@ fn checkCallArgumentCount(...@@ -6640,7 +6621,7 @@ fn checkCallArgumentCount(
6640 );6621 );
6641 errdefer msg.destroy(sema.gpa);6622 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", .{});
6644 break :msg msg;6625 break :msg msg;
6645 };6626 };
6646 return sema.failWithOwnedErrorMsg(msg);6627 return sema.failWithOwnedErrorMsg(msg);
...@@ -6666,7 +6647,7 @@ fn callBuiltin(...@@ -6666,7 +6647,7 @@ fn callBuiltin(
6666 },6647 },
6667 else => {},6648 else => {},
6668 }6649 }
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)});
6670 };6651 };
66716652
6672 const func_ty_info = mod.typeToFunc(func_ty).?;6653 const func_ty_info = mod.typeToFunc(func_ty).?;
...@@ -6942,7 +6923,7 @@ fn analyzeCall(...@@ -6942,7 +6923,7 @@ fn analyzeCall(
6942 ) catch |err| switch (err) {6923 ) catch |err| switch (err) {
6943 error.NeededSourceLocation => {6924 error.NeededSourceLocation => {
6944 _ = sema.inst_map.remove(inst);6925 _ = sema.inst_map.remove(inst);
6945 const decl = sema.mod.declPtr(block.src_decl);6926 const decl = mod.declPtr(block.src_decl);
6946 try sema.analyzeInlineCallArg(6927 try sema.analyzeInlineCallArg(
6947 block,6928 block,
6948 &child_block,6929 &child_block,
...@@ -7111,7 +7092,7 @@ fn analyzeCall(...@@ -7111,7 +7092,7 @@ fn analyzeCall(
7111 opts,7092 opts,
7112 ) catch |err| switch (err) {7093 ) catch |err| switch (err) {
7113 error.NeededSourceLocation => {7094 error.NeededSourceLocation => {
7114 const decl = sema.mod.declPtr(block.src_decl);7095 const decl = mod.declPtr(block.src_decl);
7115 _ = try sema.analyzeCallArg(7096 _ = try sema.analyzeCallArg(
7116 block,7097 block,
7117 mod.argSrc(call_src.node_offset.x, decl, i, bound_arg_src),7098 mod.argSrc(call_src.node_offset.x, decl, i, bound_arg_src),
...@@ -7126,7 +7107,7 @@ fn analyzeCall(...@@ -7126,7 +7107,7 @@ fn analyzeCall(
7126 } else {7107 } else {
7127 args[i] = sema.coerceVarArgParam(block, uncasted_arg, .unneeded) catch |err| switch (err) {7108 args[i] = sema.coerceVarArgParam(block, uncasted_arg, .unneeded) catch |err| switch (err) {
7128 error.NeededSourceLocation => {7109 error.NeededSourceLocation => {
7129 const decl = sema.mod.declPtr(block.src_decl);7110 const decl = mod.declPtr(block.src_decl);
7130 _ = try sema.coerceVarArgParam(7111 _ = try sema.coerceVarArgParam(
7131 block,7112 block,
7132 uncasted_arg,7113 uncasted_arg,
...@@ -7148,7 +7129,7 @@ fn analyzeCall(...@@ -7148,7 +7129,7 @@ fn analyzeCall(
71487129
7149 if (try sema.resolveMaybeUndefVal(func)) |func_val| {7130 if (try sema.resolveMaybeUndefVal(func)) |func_val| {
7150 if (mod.intern_pool.indexToFunc(func_val.toIntern()).unwrap()) |func_index| {7131 if (mod.intern_pool.indexToFunc(func_val.toIntern()).unwrap()) |func_index| {
7151 try sema.mod.ensureFuncBodyAnalysisQueued(func_index);7132 try mod.ensureFuncBodyAnalysisQueued(func_index);
7152 }7133 }
7153 }7134 }
71547135
...@@ -7201,17 +7182,18 @@ fn analyzeCall(...@@ -7201,17 +7182,18 @@ fn analyzeCall(
7201}7182}
72027183
7203fn handleTailCall(sema: *Sema, block: *Block, call_src: LazySrcLoc, func_ty: Type, result: Air.Inst.Ref) !Air.Inst.Ref {7184fn handleTailCall(sema: *Sema, block: *Block, call_src: LazySrcLoc, func_ty: Type, result: Air.Inst.Ref) !Air.Inst.Ref {
7204 const target = sema.mod.getTarget();7185 const mod = sema.mod;
7205 const backend = sema.mod.comp.getZigBackend();7186 const target = mod.getTarget();
7187 const backend = mod.comp.getZigBackend();
7206 if (!target_util.supportsTailCall(target, backend)) {7188 if (!target_util.supportsTailCall(target, backend)) {
7207 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", .{7189 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", .{
7208 @tagName(backend), @tagName(target.cpu.arch),7190 @tagName(backend), @tagName(target.cpu.arch),
7209 });7191 });
7210 }7192 }
7211 const func_decl = sema.mod.declPtr(sema.owner_func.?.owner_decl);7193 const func_decl = mod.declPtr(sema.owner_func.?.owner_decl);
7212 if (!func_ty.eql(func_decl.ty, sema.mod)) {7194 if (!func_ty.eql(func_decl.ty, mod)) {
7213 return sema.fail(block, call_src, "unable to perform tail call: type of function being called '{}' does not match type of calling function '{}'", .{7195 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),
7215 });7197 });
7216 }7198 }
7217 _ = try block.addUnOp(.ret, result);7199 _ = try block.addUnOp(.ret, result);
...@@ -7404,10 +7386,9 @@ fn instantiateGenericCall(...@@ -7404,10 +7386,9 @@ fn instantiateGenericCall(
7404) CompileError!Air.Inst.Ref {7386) CompileError!Air.Inst.Ref {
7405 const mod = sema.mod;7387 const mod = sema.mod;
7406 const gpa = sema.gpa;7388 const gpa = sema.gpa;
7407 const ip = &mod.intern_pool;
74087389
7409 const func_val = try sema.resolveConstValue(block, func_src, func, "generic function being called must be comptime-known");7390 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())) {
7411 .func => |function| function.index,7392 .func => |function| function.index,
7412 .ptr => |ptr| mod.declPtr(ptr.addr.decl).val.getFunctionIndex(mod).unwrap().?,7393 .ptr => |ptr| mod.declPtr(ptr.addr.decl).val.getFunctionIndex(mod).unwrap().?,
7413 else => unreachable,7394 else => unreachable,
...@@ -7467,7 +7448,7 @@ fn instantiateGenericCall(...@@ -7467,7 +7448,7 @@ fn instantiateGenericCall(
7467 if (is_comptime) {7448 if (is_comptime) {
7468 const arg_val = sema.analyzeGenericCallArgVal(block, .unneeded, uncasted_args[arg_i]) catch |err| switch (err) {7449 const arg_val = sema.analyzeGenericCallArgVal(block, .unneeded, uncasted_args[arg_i]) catch |err| switch (err) {
7469 error.NeededSourceLocation => {7450 error.NeededSourceLocation => {
7470 const decl = sema.mod.declPtr(block.src_decl);7451 const decl = mod.declPtr(block.src_decl);
7471 const arg_src = mod.argSrc(call_src.node_offset.x, decl, arg_i, bound_arg_src);7452 const arg_src = mod.argSrc(call_src.node_offset.x, decl, arg_i, bound_arg_src);
7472 _ = try sema.analyzeGenericCallArgVal(block, arg_src, uncasted_args[arg_i]);7453 _ = try sema.analyzeGenericCallArgVal(block, arg_src, uncasted_args[arg_i]);
7473 unreachable;7454 unreachable;
...@@ -7491,7 +7472,7 @@ fn instantiateGenericCall(...@@ -7491,7 +7472,7 @@ fn instantiateGenericCall(
7491 };7472 };
7492 const casted_arg = sema.coerce(block, final_arg_ty.toType(), uncasted_args[arg_i], .unneeded) catch |err| switch (err) {7473 const casted_arg = sema.coerce(block, final_arg_ty.toType(), uncasted_args[arg_i], .unneeded) catch |err| switch (err) {
7493 error.NeededSourceLocation => {7474 error.NeededSourceLocation => {
7494 const decl = sema.mod.declPtr(block.src_decl);7475 const decl = mod.declPtr(block.src_decl);
7495 const arg_src = mod.argSrc(call_src.node_offset.x, decl, arg_i, bound_arg_src);7476 const arg_src = mod.argSrc(call_src.node_offset.x, decl, arg_i, bound_arg_src);
7496 _ = try sema.coerce(block, final_arg_ty.toType(), uncasted_args[arg_i], arg_src);7477 _ = try sema.coerce(block, final_arg_ty.toType(), uncasted_args[arg_i], arg_src);
7497 unreachable;7478 unreachable;
...@@ -7500,7 +7481,7 @@ fn instantiateGenericCall(...@@ -7500,7 +7481,7 @@ fn instantiateGenericCall(
7500 };7481 };
7501 const casted_arg_val = sema.analyzeGenericCallArgVal(block, .unneeded, casted_arg) catch |err| switch (err) {7482 const casted_arg_val = sema.analyzeGenericCallArgVal(block, .unneeded, casted_arg) catch |err| switch (err) {
7502 error.NeededSourceLocation => {7483 error.NeededSourceLocation => {
7503 const decl = sema.mod.declPtr(block.src_decl);7484 const decl = mod.declPtr(block.src_decl);
7504 const arg_src = mod.argSrc(call_src.node_offset.x, decl, arg_i, bound_arg_src);7485 const arg_src = mod.argSrc(call_src.node_offset.x, decl, arg_i, bound_arg_src);
7505 _ = try sema.analyzeGenericCallArgVal(block, arg_src, casted_arg);7486 _ = try sema.analyzeGenericCallArgVal(block, arg_src, casted_arg);
7506 unreachable;7487 unreachable;
...@@ -7540,12 +7521,9 @@ fn instantiateGenericCall(...@@ -7540,12 +7521,9 @@ fn instantiateGenericCall(
7540 const new_decl_index = try mod.allocateNewDecl(namespace_index, fn_owner_decl.src_node, src_decl.src_scope);7521 const new_decl_index = try mod.allocateNewDecl(namespace_index, fn_owner_decl.src_node, src_decl.src_scope);
7541 const new_decl = mod.declPtr(new_decl_index);7522 const new_decl = mod.declPtr(new_decl_index);
7542 // TODO better names for generic function instantiations7523 // TODO better names for generic function instantiations
7543 // The ensureUnusedCapacity here protects against fn_owner_decl.name slice being7524 const decl_name = try mod.intern_pool.getOrPutStringFmt(gpa, "{}__anon_{d}", .{
7544 // reallocated during getOrPutStringFmt.7525 fn_owner_decl.name.fmt(&mod.intern_pool), @enumToInt(new_decl_index),
7545 try ip.string_bytes.ensureUnusedCapacity(gpa, ip.stringToSlice(fn_owner_decl.name).len + 20);7526 });
7546 const decl_name = ip.getOrPutStringFmt(gpa, "{s}__anon_{d}", .{
7547 ip.stringToSlice(fn_owner_decl.name), @enumToInt(new_decl_index),
7548 }) catch unreachable;
7549 new_decl.name = decl_name;7527 new_decl.name = decl_name;
7550 new_decl.src_line = fn_owner_decl.src_line;7528 new_decl.src_line = fn_owner_decl.src_line;
7551 new_decl.is_pub = fn_owner_decl.is_pub;7529 new_decl.is_pub = fn_owner_decl.is_pub;
...@@ -7634,7 +7612,7 @@ fn instantiateGenericCall(...@@ -7634,7 +7612,7 @@ fn instantiateGenericCall(
7634 &runtime_i,7612 &runtime_i,
7635 ) catch |err| switch (err) {7613 ) catch |err| switch (err) {
7636 error.NeededSourceLocation => {7614 error.NeededSourceLocation => {
7637 const decl = sema.mod.declPtr(block.src_decl);7615 const decl = mod.declPtr(block.src_decl);
7638 _ = try sema.analyzeGenericCallArg(7616 _ = try sema.analyzeGenericCallArg(
7639 block,7617 block,
7640 mod.argSrc(call_src.node_offset.x, decl, total_i, bound_arg_src),7618 mod.argSrc(call_src.node_offset.x, decl, total_i, bound_arg_src),
...@@ -7660,7 +7638,7 @@ fn instantiateGenericCall(...@@ -7660,7 +7638,7 @@ fn instantiateGenericCall(
7660 sema.owner_func.?.calls_or_awaits_errorable_fn = true;7638 sema.owner_func.?.calls_or_awaits_errorable_fn = true;
7661 }7639 }
76627640
7663 try sema.mod.ensureFuncBodyAnalysisQueued(callee_index);7641 try mod.ensureFuncBodyAnalysisQueued(callee_index);
76647642
7665 try sema.air_extra.ensureUnusedCapacity(sema.gpa, @typeInfo(Air.Call).Struct.fields.len +7643 try sema.air_extra.ensureUnusedCapacity(sema.gpa, @typeInfo(Air.Call).Struct.fields.len +
7666 runtime_args_len);7644 runtime_args_len);
...@@ -7788,7 +7766,7 @@ fn resolveGenericInstantiationType(...@@ -7788,7 +7766,7 @@ fn resolveGenericInstantiationType(
7788 if (try sema.typeRequiresComptime(arg_ty)) {7766 if (try sema.typeRequiresComptime(arg_ty)) {
7789 const arg_val = sema.resolveConstValue(block, .unneeded, arg, "") catch |err| switch (err) {7767 const arg_val = sema.resolveConstValue(block, .unneeded, arg, "") catch |err| switch (err) {
7790 error.NeededSourceLocation => {7768 error.NeededSourceLocation => {
7791 const decl = sema.mod.declPtr(block.src_decl);7769 const decl = mod.declPtr(block.src_decl);
7792 const arg_src = mod.argSrc(call_src.node_offset.x, decl, arg_i, bound_arg_src);7770 const arg_src = mod.argSrc(call_src.node_offset.x, decl, arg_i, bound_arg_src);
7793 _ = try sema.resolveConstValue(block, arg_src, arg, "argument to parameter with comptime-only type must be comptime-known");7771 _ = try sema.resolveConstValue(block, arg_src, arg, "argument to parameter with comptime-only type must be comptime-known");
7794 unreachable;7772 unreachable;
...@@ -7981,9 +7959,9 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -7981,9 +7959,9 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
7981 const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node };7959 const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node };
7982 const child_type = try sema.resolveType(block, operand_src, inst_data.operand);7960 const child_type = try sema.resolveType(block, operand_src, inst_data.operand);
7983 if (child_type.zigTypeTag(mod) == .Opaque) {7961 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)});
7985 } else if (child_type.zigTypeTag(mod) == .Null) {7963 } 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)});
7987 }7965 }
7988 const opt_type = try Type.optional(sema.arena, child_type, mod);7966 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...@@ -8059,7 +8037,7 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil
8059fn validateArrayElemType(sema: *Sema, block: *Block, elem_type: Type, elem_src: LazySrcLoc) !void {8037fn validateArrayElemType(sema: *Sema, block: *Block, elem_type: Type, elem_src: LazySrcLoc) !void {
8060 const mod = sema.mod;8038 const mod = sema.mod;
8061 if (elem_type.zigTypeTag(mod) == .Opaque) {8039 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)});
8063 } else if (elem_type.zigTypeTag(mod) == .NoReturn) {8041 } else if (elem_type.zigTypeTag(mod) == .NoReturn) {
8064 return sema.fail(block, elem_src, "array of 'noreturn' not allowed", .{});8042 return sema.fail(block, elem_src, "array of 'noreturn' not allowed", .{});
8065 }8043 }
...@@ -8095,7 +8073,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr...@@ -8095,7 +8073,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
80958073
8096 if (error_set.zigTypeTag(mod) != .ErrorSet) {8074 if (error_set.zigTypeTag(mod) != .ErrorSet) {
8097 return sema.fail(block, lhs_src, "expected error set type, found '{}'", .{8075 return sema.fail(block, lhs_src, "expected error set type, found '{}'", .{
8098 error_set.fmt(sema.mod),8076 error_set.fmt(mod),
8099 });8077 });
8100 }8078 }
8101 try sema.validateErrorUnionPayloadType(block, payload, rhs_src);8079 try sema.validateErrorUnionPayloadType(block, payload, rhs_src);
...@@ -8107,11 +8085,11 @@ fn validateErrorUnionPayloadType(sema: *Sema, block: *Block, payload_ty: Type, p...@@ -8107,11 +8085,11 @@ fn validateErrorUnionPayloadType(sema: *Sema, block: *Block, payload_ty: Type, p
8107 const mod = sema.mod;8085 const mod = sema.mod;
8108 if (payload_ty.zigTypeTag(mod) == .Opaque) {8086 if (payload_ty.zigTypeTag(mod) == .Opaque) {
8109 return sema.fail(block, payload_src, "error union with payload of opaque type '{}' not allowed", .{8087 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),
8111 });8089 });
8112 } else if (payload_ty.zigTypeTag(mod) == .ErrorSet) {8090 } else if (payload_ty.zigTypeTag(mod) == .ErrorSet) {
8113 return sema.fail(block, payload_src, "error union with payload of error set type '{}' not allowed", .{8091 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),
8115 });8093 });
8116 }8094 }
8117}8095}
...@@ -8123,7 +8101,7 @@ fn zirErrorValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -8123,7 +8101,7 @@ fn zirErrorValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
8123 const name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code));8101 const name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code));
8124 _ = try mod.getErrorValue(name);8102 _ = try mod.getErrorValue(name);
8125 // Create an error set type with only this error value, and return the value.8103 // 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);
8127 return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{8105 return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{
8128 .ty = error_set_type.toIntern(),8106 .ty = error_set_type.toIntern(),
8129 .name = name,8107 .name = name,
...@@ -8231,9 +8209,9 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr...@@ -8231,9 +8209,9 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
8231 const lhs_ty = try sema.analyzeAsType(block, lhs_src, lhs);8209 const lhs_ty = try sema.analyzeAsType(block, lhs_src, lhs);
8232 const rhs_ty = try sema.analyzeAsType(block, rhs_src, rhs);8210 const rhs_ty = try sema.analyzeAsType(block, rhs_src, rhs);
8233 if (lhs_ty.zigTypeTag(mod) != .ErrorSet)8211 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)});
8235 if (rhs_ty.zigTypeTag(mod) != .ErrorSet)8213 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
8238 // Anything merged with anyerror is anyerror.8216 // Anything merged with anyerror is anyerror.
8239 if (lhs_ty.toIntern() == .anyerror_type or rhs_ty.toIntern() == .anyerror_type) {8217 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...@@ -8296,7 +8274,7 @@ fn zirEnumToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
8296 },8274 },
8297 else => {8275 else => {
8298 return sema.fail(block, operand_src, "expected enum or tagged union, found '{}'", .{8276 return sema.fail(block, operand_src, "expected enum or tagged union, found '{}'", .{
8299 operand_ty.fmt(sema.mod),8277 operand_ty.fmt(mod),
8300 });8278 });
8301 },8279 },
8302 };8280 };
...@@ -8328,7 +8306,7 @@ fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -8328,7 +8306,7 @@ fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
8328 const operand = try sema.resolveInst(extra.rhs);8306 const operand = try sema.resolveInst(extra.rhs);
83298307
8330 if (dest_ty.zigTypeTag(mod) != .Enum) {8308 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)});
8332 }8310 }
8333 _ = try sema.checkIntType(block, operand_src, sema.typeOf(operand));8311 _ = 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...@@ -8343,7 +8321,7 @@ fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
8343 block,8321 block,
8344 src,8322 src,
8345 "int value '{}' out of range of non-exhaustive enum '{}'",8323 "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) },
8347 );8325 );
8348 errdefer msg.destroy(sema.gpa);8326 errdefer msg.destroy(sema.gpa);
8349 try sema.addDeclaredHereNote(msg, dest_ty);8327 try sema.addDeclaredHereNote(msg, dest_ty);
...@@ -8360,7 +8338,7 @@ fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -8360,7 +8338,7 @@ fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
8360 block,8338 block,
8361 src,8339 src,
8362 "enum '{}' has no tag with value '{}'",8340 "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) },
8364 );8342 );
8365 errdefer msg.destroy(sema.gpa);8343 errdefer msg.destroy(sema.gpa);
8366 try sema.addDeclaredHereNote(msg, dest_ty);8344 try sema.addDeclaredHereNote(msg, dest_ty);
...@@ -8383,7 +8361,7 @@ fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -8383,7 +8361,7 @@ fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
8383 try sema.requireRuntimeBlock(block, src, operand_src);8361 try sema.requireRuntimeBlock(block, src, operand_src);
8384 const result = try block.addTyOp(.intcast, dest_ty, operand);8362 const result = try block.addTyOp(.intcast, dest_ty, operand);
8385 if (block.wantSafety() and !dest_ty.isNonexhaustiveEnum(mod) and8363 if (block.wantSafety() and !dest_ty.isNonexhaustiveEnum(mod) and
8386 sema.mod.backendSupportsFeature(.is_named_enum_value))8364 mod.backendSupportsFeature(.is_named_enum_value))
8387 {8365 {
8388 const ok = try block.addUnOp(.is_named_enum_value, result);8366 const ok = try block.addUnOp(.is_named_enum_value, result);
8389 try sema.addSafetyCheck(block, ok, .invalid_enum_value);8367 try sema.addSafetyCheck(block, ok, .invalid_enum_value);
...@@ -8422,11 +8400,11 @@ fn analyzeOptionalPayloadPtr(...@@ -8422,11 +8400,11 @@ fn analyzeOptionalPayloadPtr(
84228400
8423 const opt_type = optional_ptr_ty.childType(mod);8401 const opt_type = optional_ptr_ty.childType(mod);
8424 if (opt_type.zigTypeTag(mod) != .Optional) {8402 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)});
8426 }8404 }
84278405
8428 const child_type = opt_type.optionalChild(mod);8406 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, .{
8430 .pointee_type = child_type,8408 .pointee_type = child_type,
8431 .mutable = !optional_ptr_ty.isConstPtr(mod),8409 .mutable = !optional_ptr_ty.isConstPtr(mod),
8432 .@"addrspace" = optional_ptr_ty.ptrAddressSpace(mod),8410 .@"addrspace" = optional_ptr_ty.ptrAddressSpace(mod),
...@@ -8493,7 +8471,7 @@ fn zirOptionalPayload(...@@ -8493,7 +8471,7 @@ fn zirOptionalPayload(
8493 // TODO https://github.com/ziglang/zig/issues/65978471 // TODO https://github.com/ziglang/zig/issues/6597
8494 if (true) break :t operand_ty;8472 if (true) break :t operand_ty;
8495 const ptr_info = operand_ty.ptrInfo(mod);8473 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, .{
8497 .pointee_type = ptr_info.pointee_type,8475 .pointee_type = ptr_info.pointee_type,
8498 .@"align" = ptr_info.@"align",8476 .@"align" = ptr_info.@"align",
8499 .@"addrspace" = ptr_info.@"addrspace",8477 .@"addrspace" = ptr_info.@"addrspace",
...@@ -8538,7 +8516,7 @@ fn zirErrUnionPayload(...@@ -8538,7 +8516,7 @@ fn zirErrUnionPayload(
8538 const err_union_ty = sema.typeOf(operand);8516 const err_union_ty = sema.typeOf(operand);
8539 if (err_union_ty.zigTypeTag(mod) != .ErrorUnion) {8517 if (err_union_ty.zigTypeTag(mod) != .ErrorUnion) {
8540 return sema.fail(block, operand_src, "expected error union type, found '{}'", .{8518 return sema.fail(block, operand_src, "expected error union type, found '{}'", .{
8541 err_union_ty.fmt(sema.mod),8519 err_union_ty.fmt(mod),
8542 });8520 });
8543 }8521 }
8544 return sema.analyzeErrUnionPayload(block, src, err_union_ty, operand, operand_src, false);8522 return sema.analyzeErrUnionPayload(block, src, err_union_ty, operand, operand_src, false);
...@@ -8556,8 +8534,8 @@ fn analyzeErrUnionPayload(...@@ -8556,8 +8534,8 @@ fn analyzeErrUnionPayload(
8556 const mod = sema.mod;8534 const mod = sema.mod;
8557 const payload_ty = err_union_ty.errorUnionPayload(mod);8535 const payload_ty = err_union_ty.errorUnionPayload(mod);
8558 if (try sema.resolveDefinedValue(block, operand_src, operand)) |val| {8536 if (try sema.resolveDefinedValue(block, operand_src, operand)) |val| {
8559 if (val.getError(mod)) |name| {8537 if (val.getErrorName(mod).unwrap()) |name| {
8560 return sema.fail(block, src, "caught unexpected error '{s}'", .{name});8538 return sema.fail(block, src, "caught unexpected error '{}'", .{name.fmt(&mod.intern_pool)});
8561 }8539 }
8562 return sema.addConstant(8540 return sema.addConstant(
8563 payload_ty,8541 payload_ty,
...@@ -8607,13 +8585,13 @@ fn analyzeErrUnionPayloadPtr(...@@ -8607,13 +8585,13 @@ fn analyzeErrUnionPayloadPtr(
86078585
8608 if (operand_ty.childType(mod).zigTypeTag(mod) != .ErrorUnion) {8586 if (operand_ty.childType(mod).zigTypeTag(mod) != .ErrorUnion) {
8609 return sema.fail(block, src, "expected error union type, found '{}'", .{8587 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),
8611 });8589 });
8612 }8590 }
86138591
8614 const err_union_ty = operand_ty.childType(mod);8592 const err_union_ty = operand_ty.childType(mod);
8615 const payload_ty = err_union_ty.errorUnionPayload(mod);8593 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, .{
8617 .pointee_type = payload_ty,8595 .pointee_type = payload_ty,
8618 .mutable = !operand_ty.isConstPtr(mod),8596 .mutable = !operand_ty.isConstPtr(mod),
8619 .@"addrspace" = operand_ty.ptrAddressSpace(mod),8597 .@"addrspace" = operand_ty.ptrAddressSpace(mod),
...@@ -8634,8 +8612,8 @@ fn analyzeErrUnionPayloadPtr(...@@ -8634,8 +8612,8 @@ fn analyzeErrUnionPayloadPtr(
8634 } })).toValue());8612 } })).toValue());
8635 }8613 }
8636 if (try sema.pointerDeref(block, src, ptr_val, operand_ty)) |val| {8614 if (try sema.pointerDeref(block, src, ptr_val, operand_ty)) |val| {
8637 if (val.getError(mod)) |name| {8615 if (val.getErrorName(mod).unwrap()) |name| {
8638 return sema.fail(block, src, "caught unexpected error '{s}'", .{name});8616 return sema.fail(block, src, "caught unexpected error '{}'", .{name.fmt(&mod.intern_pool)});
8639 }8617 }
8640 return sema.addConstant(operand_pointer_ty, (try mod.intern(.{ .ptr = .{8618 return sema.addConstant(operand_pointer_ty, (try mod.intern(.{ .ptr = .{
8641 .ty = operand_pointer_ty.toIntern(),8619 .ty = operand_pointer_ty.toIntern(),
...@@ -8676,7 +8654,7 @@ fn analyzeErrUnionCode(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air...@@ -8676,7 +8654,7 @@ fn analyzeErrUnionCode(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air
8676 const operand_ty = sema.typeOf(operand);8654 const operand_ty = sema.typeOf(operand);
8677 if (operand_ty.zigTypeTag(mod) != .ErrorUnion) {8655 if (operand_ty.zigTypeTag(mod) != .ErrorUnion) {
8678 return sema.fail(block, src, "expected error union type, found '{}'", .{8656 return sema.fail(block, src, "expected error union type, found '{}'", .{
8679 operand_ty.fmt(sema.mod),8657 operand_ty.fmt(mod),
8680 });8658 });
8681 }8659 }
86828660
...@@ -8707,7 +8685,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE...@@ -8707,7 +8685,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
87078685
8708 if (operand_ty.childType(mod).zigTypeTag(mod) != .ErrorUnion) {8686 if (operand_ty.childType(mod).zigTypeTag(mod) != .ErrorUnion) {
8709 return sema.fail(block, src, "expected error union type, found '{}'", .{8687 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),
8711 });8689 });
8712 }8690 }
87138691
...@@ -8715,7 +8693,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE...@@ -8715,7 +8693,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
87158693
8716 if (try sema.resolveDefinedValue(block, src, operand)) |pointer_val| {8694 if (try sema.resolveDefinedValue(block, src, operand)) |pointer_val| {
8717 if (try sema.pointerDeref(block, src, pointer_val, operand_ty)) |val| {8695 if (try sema.pointerDeref(block, src, pointer_val, operand_ty)) |val| {
8718 assert(val.getError(mod) != null);8696 assert(val.getErrorName(mod) != .none);
8719 return sema.addConstant(result_ty, val);8697 return sema.addConstant(result_ty, val);
8720 }8698 }
8721 }8699 }
...@@ -8968,7 +8946,7 @@ fn funcCommon(...@@ -8968,7 +8946,7 @@ fn funcCommon(
8968 };8946 };
8969 errdefer if (destroy_fn_on_error) mod.destroyFunc(new_func_index);8947 errdefer if (destroy_fn_on_error) mod.destroyFunc(new_func_index);
89708948
8971 const target = sema.mod.getTarget();8949 const target = mod.getTarget();
8972 const fn_ty: Type = fn_ty: {8950 const fn_ty: Type = fn_ty: {
8973 // In the case of generic calling convention, or generic alignment, we use8951 // In the case of generic calling convention, or generic alignment, we use
8974 // default values which are only meaningful for the generic function, *not*8952 // default values which are only meaningful for the generic function, *not*
...@@ -8995,7 +8973,7 @@ fn funcCommon(...@@ -8995,7 +8973,7 @@ fn funcCommon(
8995 is_noalias,8973 is_noalias,
8996 ) catch |err| switch (err) {8974 ) catch |err| switch (err) {
8997 error.NeededSourceLocation => {8975 error.NeededSourceLocation => {
8998 const decl = sema.mod.declPtr(block.src_decl);8976 const decl = mod.declPtr(block.src_decl);
8999 try sema.analyzeParameter(8977 try sema.analyzeParameter(
9000 block,8978 block,
9001 Module.paramSrc(src_node_offset, mod, decl, i),8979 Module.paramSrc(src_node_offset, mod, decl, i),
...@@ -9040,7 +9018,7 @@ fn funcCommon(...@@ -9040,7 +9018,7 @@ fn funcCommon(
9040 const opaque_str = if (return_type.zigTypeTag(mod) == .Opaque) "opaque " else "";9018 const opaque_str = if (return_type.zigTypeTag(mod) == .Opaque) "opaque " else "";
9041 const msg = msg: {9019 const msg = msg: {
9042 const msg = try sema.errMsg(block, ret_ty_src, "{s}return type '{}' not allowed", .{9020 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),
9044 });9022 });
9045 errdefer msg.destroy(gpa);9023 errdefer msg.destroy(gpa);
90469024
...@@ -9054,11 +9032,11 @@ fn funcCommon(...@@ -9054,11 +9032,11 @@ fn funcCommon(
9054 {9032 {
9055 const msg = msg: {9033 const msg = msg: {
9056 const msg = try sema.errMsg(block, ret_ty_src, "return type '{}' not allowed in function with calling convention '{s}'", .{9034 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),
9058 });9036 });
9059 errdefer msg.destroy(gpa);9037 errdefer msg.destroy(gpa);
90609038
9061 const src_decl = sema.mod.declPtr(block.src_decl);9039 const src_decl = mod.declPtr(block.src_decl);
9062 try sema.explainWhyTypeIsNotExtern(msg, ret_ty_src.toSrcLoc(src_decl, mod), return_type, .ret_ty);9040 try sema.explainWhyTypeIsNotExtern(msg, ret_ty_src.toSrcLoc(src_decl, mod), return_type, .ret_ty);
90639041
9064 try sema.addDeclaredHereNote(msg, return_type);9042 try sema.addDeclaredHereNote(msg, return_type);
...@@ -9077,7 +9055,7 @@ fn funcCommon(...@@ -9077,7 +9055,7 @@ fn funcCommon(
9077 block,9055 block,
9078 ret_ty_src,9056 ret_ty_src,
9079 "function with comptime-only return type '{}' requires all parameters to be comptime",9057 "function with comptime-only return type '{}' requires all parameters to be comptime",
9080 .{return_type.fmt(sema.mod)},9058 .{return_type.fmt(mod)},
9081 );9059 );
9082 try sema.explainWhyTypeIsComptime(msg, ret_ty_src.toSrcLoc(sema.owner_decl, mod), return_type);9060 try sema.explainWhyTypeIsComptime(msg, ret_ty_src.toSrcLoc(sema.owner_decl, mod), return_type);
90839061
...@@ -9102,7 +9080,7 @@ fn funcCommon(...@@ -9102,7 +9080,7 @@ fn funcCommon(
9102 return sema.failWithOwnedErrorMsg(msg);9080 return sema.failWithOwnedErrorMsg(msg);
9103 }9081 }
91049082
9105 const arch = sema.mod.getTarget().cpu.arch;9083 const arch = mod.getTarget().cpu.arch;
9106 if (switch (cc_resolved) {9084 if (switch (cc_resolved) {
9107 .Unspecified, .C, .Naked, .Async, .Inline => null,9085 .Unspecified, .C, .Naked, .Async, .Inline => null,
9108 .Interrupt => switch (arch) {9086 .Interrupt => switch (arch) {
...@@ -9542,7 +9520,7 @@ fn zirPtrToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -9542,7 +9520,7 @@ fn zirPtrToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
9542 const ptr = try sema.resolveInst(inst_data.operand);9520 const ptr = try sema.resolveInst(inst_data.operand);
9543 const ptr_ty = sema.typeOf(ptr);9521 const ptr_ty = sema.typeOf(ptr);
9544 if (!ptr_ty.isPtrAtRuntime(mod)) {9522 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)});
9546 }9524 }
9547 if (try sema.resolveMaybeUndefValIntable(ptr)) |ptr_val| {9525 if (try sema.resolveMaybeUndefValIntable(ptr)) |ptr_val| {
9548 return sema.addConstant(9526 return sema.addConstant(
...@@ -9797,14 +9775,14 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -9797,14 +9775,14 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
9797 .Type,9775 .Type,
9798 .Undefined,9776 .Undefined,
9799 .Void,9777 .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
9802 .Enum => {9780 .Enum => {
9803 const msg = msg: {9781 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)});
9805 errdefer msg.destroy(sema.gpa);9783 errdefer msg.destroy(sema.gpa);
9806 switch (operand_ty.zigTypeTag(mod)) {9784 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)}),
9808 else => {},9786 else => {},
9809 }9787 }
98109788
...@@ -9815,11 +9793,11 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -9815,11 +9793,11 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
98159793
9816 .Pointer => {9794 .Pointer => {
9817 const msg = msg: {9795 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)});
9819 errdefer msg.destroy(sema.gpa);9797 errdefer msg.destroy(sema.gpa);
9820 switch (operand_ty.zigTypeTag(mod)) {9798 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)}),9799 .Int, .ComptimeInt => try sema.errNote(block, dest_ty_src, msg, "use @intToPtr to cast from '{}'", .{operand_ty.fmt(mod)}),
9822 .Pointer => try sema.errNote(block, dest_ty_src, msg, "use @ptrCast to cast from '{}'", .{operand_ty.fmt(sema.mod)}),9800 .Pointer => try sema.errNote(block, dest_ty_src, msg, "use @ptrCast to cast from '{}'", .{operand_ty.fmt(mod)}),
9823 else => {},9801 else => {},
9824 }9802 }
98259803
...@@ -9834,7 +9812,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -9834,7 +9812,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
9834 else => unreachable,9812 else => unreachable,
9835 };9813 };
9836 return sema.fail(block, dest_ty_src, "cannot @bitCast to '{}'; {s} does not have a guaranteed in-memory layout", .{9814 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,
9838 });9816 });
9839 },9817 },
98409818
...@@ -9861,14 +9839,14 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -9861,14 +9839,14 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
9861 .Type,9839 .Type,
9862 .Undefined,9840 .Undefined,
9863 .Void,9841 .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
9866 .Enum => {9844 .Enum => {
9867 const msg = msg: {9845 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)});
9869 errdefer msg.destroy(sema.gpa);9847 errdefer msg.destroy(sema.gpa);
9870 switch (dest_ty.zigTypeTag(mod)) {9848 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)}),
9872 else => {},9850 else => {},
9873 }9851 }
98749852
...@@ -9878,11 +9856,11 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -9878,11 +9856,11 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
9878 },9856 },
9879 .Pointer => {9857 .Pointer => {
9880 const msg = msg: {9858 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)});
9882 errdefer msg.destroy(sema.gpa);9860 errdefer msg.destroy(sema.gpa);
9883 switch (dest_ty.zigTypeTag(mod)) {9861 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)}),9862 .Int, .ComptimeInt => try sema.errNote(block, operand_src, msg, "use @ptrToInt to cast to '{}'", .{dest_ty.fmt(mod)}),
9885 .Pointer => try sema.errNote(block, operand_src, msg, "use @ptrCast to cast to '{}'", .{dest_ty.fmt(sema.mod)}),9863 .Pointer => try sema.errNote(block, operand_src, msg, "use @ptrCast to cast to '{}'", .{dest_ty.fmt(mod)}),
9886 else => {},9864 else => {},
9887 }9865 }
98889866
...@@ -9897,7 +9875,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -9897,7 +9875,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
9897 else => unreachable,9875 else => unreachable,
9898 };9876 };
9899 return sema.fail(block, operand_src, "cannot @bitCast from '{}'; {s} does not have a guaranteed in-memory layout", .{9877 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,
9901 });9879 });
9902 },9880 },
99039881
...@@ -9924,7 +9902,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -9924,7 +9902,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
9924 const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs);9902 const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs);
9925 const operand = try sema.resolveInst(extra.rhs);9903 const operand = try sema.resolveInst(extra.rhs);
99269904
9927 const target = sema.mod.getTarget();9905 const target = mod.getTarget();
9928 const dest_is_comptime_float = switch (dest_ty.zigTypeTag(mod)) {9906 const dest_is_comptime_float = switch (dest_ty.zigTypeTag(mod)) {
9929 .ComptimeFloat => true,9907 .ComptimeFloat => true,
9930 .Float => false,9908 .Float => false,
...@@ -9932,7 +9910,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -9932,7 +9910,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
9932 block,9910 block,
9933 dest_ty_src,9911 dest_ty_src,
9934 "expected float type, found '{}'",9912 "expected float type, found '{}'",
9935 .{dest_ty.fmt(sema.mod)},9913 .{dest_ty.fmt(mod)},
9936 ),9914 ),
9937 };9915 };
99389916
...@@ -9943,7 +9921,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -9943,7 +9921,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
9943 block,9921 block,
9944 operand_src,9922 operand_src,
9945 "expected float type, found '{}'",9923 "expected float type, found '{}'",
9946 .{operand_ty.fmt(sema.mod)},9924 .{operand_ty.fmt(mod)},
9947 ),9925 ),
9948 }9926 }
99499927
...@@ -10002,7 +9980,7 @@ fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -10002,7 +9980,7 @@ fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
10002 const capture_src: LazySrcLoc = .{ .for_capture_from_input = inst_data.src_node };9980 const capture_src: LazySrcLoc = .{ .for_capture_from_input = inst_data.src_node };
10003 const msg = msg: {9981 const msg = msg: {
10004 const msg = try sema.errMsg(block, capture_src, "pointer capture of non pointer type '{}'", .{9982 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),
10006 });9984 });
10007 errdefer msg.destroy(sema.gpa);9985 errdefer msg.destroy(sema.gpa);
10008 if (indexable_ty.zigTypeTag(mod) == .Array) {9986 if (indexable_ty.zigTypeTag(mod) == .Array) {
...@@ -10143,12 +10121,12 @@ fn zirSwitchCapture(...@@ -10143,12 +10121,12 @@ fn zirSwitchCapture(
10143 const item_val = sema.resolveConstValue(block, .unneeded, block.inline_case_capture, undefined) catch unreachable;10121 const item_val = sema.resolveConstValue(block, .unneeded, block.inline_case_capture, undefined) catch unreachable;
10144 const resolved_item_val = try sema.resolveLazyValue(item_val);10122 const resolved_item_val = try sema.resolveLazyValue(item_val);
10145 if (operand_ty.zigTypeTag(mod) == .Union) {10123 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).?);
10147 const union_obj = mod.typeToUnion(operand_ty).?;10125 const union_obj = mod.typeToUnion(operand_ty).?;
10148 const field_ty = union_obj.fields.values()[field_index].ty;10126 const field_ty = union_obj.fields.values()[field_index].ty;
10149 if (try sema.resolveDefinedValue(block, sema.src, operand_ptr)) |union_val| {10127 if (try sema.resolveDefinedValue(block, sema.src, operand_ptr)) |union_val| {
10150 if (is_ref) {10128 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, .{
10152 .pointee_type = field_ty,10130 .pointee_type = field_ty,
10153 .mutable = operand_ptr_ty.ptrIsMutable(mod),10131 .mutable = operand_ptr_ty.ptrIsMutable(mod),
10154 .@"volatile" = operand_ptr_ty.isVolatilePtr(mod),10132 .@"volatile" = operand_ptr_ty.isVolatilePtr(mod),
...@@ -10168,7 +10146,7 @@ fn zirSwitchCapture(...@@ -10168,7 +10146,7 @@ fn zirSwitchCapture(
10168 );10146 );
10169 }10147 }
10170 if (is_ref) {10148 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, .{
10172 .pointee_type = field_ty,10150 .pointee_type = field_ty,
10173 .mutable = operand_ptr_ty.ptrIsMutable(mod),10151 .mutable = operand_ptr_ty.ptrIsMutable(mod),
10174 .@"volatile" = operand_ptr_ty.isVolatilePtr(mod),10152 .@"volatile" = operand_ptr_ty.isVolatilePtr(mod),
...@@ -10221,7 +10199,7 @@ fn zirSwitchCapture(...@@ -10221,7 +10199,7 @@ fn zirSwitchCapture(
10221 // Previous switch validation ensured this will succeed10199 // Previous switch validation ensured this will succeed
10222 const first_item_val = sema.resolveConstValue(block, .unneeded, first_item, "") catch unreachable;10200 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).?);
10225 const first_field = union_obj.fields.values()[first_field_index];10203 const first_field = union_obj.fields.values()[first_field_index];
1022610204
10227 for (items[1..], 0..) |item, i| {10205 for (items[1..], 0..) |item, i| {
...@@ -10229,22 +10207,22 @@ fn zirSwitchCapture(...@@ -10229,22 +10207,22 @@ fn zirSwitchCapture(
10229 // Previous switch validation ensured this will succeed10207 // Previous switch validation ensured this will succeed
10230 const item_val = sema.resolveConstValue(block, .unneeded, item_ref, "") catch unreachable;10208 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).?;
10233 const field = union_obj.fields.values()[field_index];10211 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)) {
10235 const msg = msg: {10213 const msg = msg: {
10236 const raw_capture_src = Module.SwitchProngSrc{ .multi_capture = capture_info.prong_index };10214 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
10239 const msg = try sema.errMsg(block, capture_src, "capture group with incompatible types", .{});10217 const msg = try sema.errMsg(block, capture_src, "capture group with incompatible types", .{});
10240 errdefer msg.destroy(gpa);10218 errdefer msg.destroy(gpa);
1024110219
10242 const raw_first_item_src = Module.SwitchProngSrc{ .multi = .{ .prong = capture_info.prong_index, .item = 0 } };10220 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);
10244 const raw_item_src = Module.SwitchProngSrc{ .multi = .{ .prong = capture_info.prong_index, .item = 1 + @intCast(u32, i) } };10222 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);10223 const item_src = raw_item_src.resolve(mod, 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)});10224 try sema.errNote(block, first_item_src, msg, "type '{}' here", .{first_field.ty.fmt(mod)});
10247 try sema.errNote(block, item_src, msg, "type '{}' here", .{field.ty.fmt(sema.mod)});10225 try sema.errNote(block, item_src, msg, "type '{}' here", .{field.ty.fmt(mod)});
10248 break :msg msg;10226 break :msg msg;
10249 };10227 };
10250 return sema.failWithOwnedErrorMsg(msg);10228 return sema.failWithOwnedErrorMsg(msg);
...@@ -10252,7 +10230,7 @@ fn zirSwitchCapture(...@@ -10252,7 +10230,7 @@ fn zirSwitchCapture(
10252 }10230 }
1025310231
10254 if (is_ref) {10232 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, .{
10256 .pointee_type = first_field.ty,10234 .pointee_type = first_field.ty,
10257 .@"addrspace" = .generic,10235 .@"addrspace" = .generic,
10258 .mutable = operand_ptr_ty.ptrIsMutable(mod),10236 .mutable = operand_ptr_ty.ptrIsMutable(mod),
...@@ -10288,8 +10266,7 @@ fn zirSwitchCapture(...@@ -10288,8 +10266,7 @@ fn zirSwitchCapture(
10288 const item_ref = try sema.resolveInst(item);10266 const item_ref = try sema.resolveInst(item);
10289 // Previous switch validation ensured this will succeed10267 // Previous switch validation ensured this will succeed
10290 const item_val = sema.resolveConstLazyValue(block, .unneeded, item_ref, "") catch unreachable;10268 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).?);10269 names.putAssumeCapacityNoClobber(item_val.getErrorName(mod).unwrap().?, {});
10292 names.putAssumeCapacityNoClobber(name_ip, {});
10293 }10270 }
10294 const else_error_ty = try mod.errorSetFromUnsortedNames(names.keys());10271 const else_error_ty = try mod.errorSetFromUnsortedNames(names.keys());
1029510272
...@@ -10299,7 +10276,7 @@ fn zirSwitchCapture(...@@ -10299,7 +10276,7 @@ fn zirSwitchCapture(
10299 // Previous switch validation ensured this will succeed10276 // Previous switch validation ensured this will succeed
10300 const item_val = sema.resolveConstLazyValue(block, .unneeded, item_ref, "") catch unreachable;10277 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().?);
10303 return sema.bitCast(block, item_ty, operand, operand_src, null);10280 return sema.bitCast(block, item_ty, operand, operand_src, null);
10304 }10281 }
10305 },10282 },
...@@ -10331,7 +10308,7 @@ fn zirSwitchCaptureTag(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile...@@ -10331,7 +10308,7 @@ fn zirSwitchCaptureTag(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile
10331 if (operand_ty.zigTypeTag(mod) != .Union) {10308 if (operand_ty.zigTypeTag(mod) != .Union) {
10332 const msg = msg: {10309 const msg = msg: {
10333 const msg = try sema.errMsg(block, src, "cannot capture tag of non-union type '{}'", .{10310 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),
10335 });10312 });
10336 errdefer msg.destroy(sema.gpa);10313 errdefer msg.destroy(sema.gpa);
10337 try sema.addDeclaredHereNote(msg, operand_ty);10314 try sema.addDeclaredHereNote(msg, operand_ty);
...@@ -10375,7 +10352,7 @@ fn zirSwitchCond(...@@ -10375,7 +10352,7 @@ fn zirSwitchCond(
10375 .Enum,10352 .Enum,
10376 => {10353 => {
10377 if (operand_ty.isSlice(mod)) {10354 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)});
10379 }10356 }
10380 if ((try sema.typeHasOnePossibleValue(operand_ty))) |opv| {10357 if ((try sema.typeHasOnePossibleValue(operand_ty))) |opv| {
10381 return sema.addConstant(operand_ty, opv);10358 return sema.addConstant(operand_ty, opv);
...@@ -10389,8 +10366,8 @@ fn zirSwitchCond(...@@ -10389,8 +10366,8 @@ fn zirSwitchCond(
10389 const msg = msg: {10366 const msg = msg: {
10390 const msg = try sema.errMsg(block, src, "switch on union with no attached enum", .{});10367 const msg = try sema.errMsg(block, src, "switch on union with no attached enum", .{});
10391 errdefer msg.destroy(sema.gpa);10368 errdefer msg.destroy(sema.gpa);
10392 if (union_ty.declSrcLocOrNull(sema.mod)) |union_src| {10369 if (union_ty.declSrcLocOrNull(mod)) |union_src| {
10393 try sema.mod.errNoteNonLazy(union_src, msg, "consider 'union(enum)' here", .{});10370 try mod.errNoteNonLazy(union_src, msg, "consider 'union(enum)' here", .{});
10394 }10371 }
10395 break :msg msg;10372 break :msg msg;
10396 };10373 };
...@@ -10410,11 +10387,11 @@ fn zirSwitchCond(...@@ -10410,11 +10387,11 @@ fn zirSwitchCond(
10410 .Vector,10387 .Vector,
10411 .Frame,10388 .Frame,
10412 .AnyFrame,10389 .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)}),
10414 }10391 }
10415}10392}
1041610393
10417const SwitchErrorSet = std.StringHashMap(Module.SwitchProngSrc);10394const SwitchErrorSet = std.AutoHashMap(InternPool.NullTerminatedString, Module.SwitchProngSrc);
1041810395
10419fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {10396fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
10420 const tracy = trace(@src());10397 const tracy = trace(@src());
...@@ -10593,8 +10570,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -10593,8 +10570,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
10593 operand_ty,10570 operand_ty,
10594 i,10571 i,
10595 msg,10572 msg,
10596 "unhandled enumeration value: '{s}'",10573 "unhandled enumeration value: '{}'",
10597 .{ip.stringToSlice(field_name)},10574 .{field_name.fmt(&mod.intern_pool)},
10598 );10575 );
10599 }10576 }
10600 try mod.errNoteNonLazy(10577 try mod.errNoteNonLazy(
...@@ -10677,8 +10654,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -10677,8 +10654,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
10677 var maybe_msg: ?*Module.ErrorMsg = null;10654 var maybe_msg: ?*Module.ErrorMsg = null;
10678 errdefer if (maybe_msg) |msg| msg.destroy(sema.gpa);10655 errdefer if (maybe_msg) |msg| msg.destroy(sema.gpa);
1067910656
10680 for (operand_ty.errorSetNames(mod)) |error_name_ip| {10657 for (operand_ty.errorSetNames(mod)) |error_name| {
10681 const error_name = ip.stringToSlice(error_name_ip);
10682 if (!seen_errors.contains(error_name) and special_prong != .@"else") {10658 if (!seen_errors.contains(error_name) and special_prong != .@"else") {
10683 const msg = maybe_msg orelse blk: {10659 const msg = maybe_msg orelse blk: {
10684 maybe_msg = try sema.errMsg(10660 maybe_msg = try sema.errMsg(
...@@ -10694,8 +10670,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -10694,8 +10670,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
10694 block,10670 block,
10695 src,10671 src,
10696 msg,10672 msg,
10697 "unhandled error value: 'error.{s}'",10673 "unhandled error value: 'error.{}'",
10698 .{error_name},10674 .{error_name.fmt(ip)},
10699 );10675 );
10700 }10676 }
10701 }10677 }
...@@ -10746,11 +10722,10 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -10746,11 +10722,10 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
10746 const error_names = operand_ty.errorSetNames(mod);10722 const error_names = operand_ty.errorSetNames(mod);
10747 var names: Module.Fn.InferredErrorSet.NameMap = .{};10723 var names: Module.Fn.InferredErrorSet.NameMap = .{};
10748 try names.ensureUnusedCapacity(sema.arena, error_names.len);10724 try names.ensureUnusedCapacity(sema.arena, error_names.len);
10749 for (error_names) |error_name_ip| {10725 for (error_names) |error_name| {
10750 const error_name = ip.stringToSlice(error_name_ip);
10751 if (seen_errors.contains(error_name)) continue;10726 if (seen_errors.contains(error_name)) continue;
1075210727
10753 names.putAssumeCapacityNoClobber(error_name_ip, {});10728 names.putAssumeCapacityNoClobber(error_name, {});
10754 }10729 }
10755 // No need to keep the hash map metadata correct; here we10730 // No need to keep the hash map metadata correct; here we
10756 // extract the (sorted) keys only.10731 // extract the (sorted) keys only.
...@@ -11500,14 +11475,13 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -11500,14 +11475,13 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
11500 });11475 });
11501 }11476 }
11502 for (0..operand_ty.errorSetNames(mod).len) |i| {11477 for (0..operand_ty.errorSetNames(mod).len) |i| {
11503 const error_name_ip = operand_ty.errorSetNames(mod)[i];11478 const error_name = operand_ty.errorSetNames(mod)[i];
11504 const error_name = mod.intern_pool.stringToSlice(error_name_ip);
11505 if (seen_errors.contains(error_name)) continue;11479 if (seen_errors.contains(error_name)) continue;
11506 cases_len += 1;11480 cases_len += 1;
1150711481
11508 const item_val = try mod.intern(.{ .err = .{11482 const item_val = try mod.intern(.{ .err = .{
11509 .ty = operand_ty.toIntern(),11483 .ty = operand_ty.toIntern(),
11510 .name = error_name_ip,11484 .name = error_name,
11511 } });11485 } });
11512 const item_ref = try sema.addConstant(operand_ty, item_val.toValue());11486 const item_ref = try sema.addConstant(operand_ty, item_val.toValue());
11513 case_block.inline_case_capture = item_ref;11487 case_block.inline_case_capture = item_ref;
...@@ -11754,7 +11728,7 @@ fn resolveSwitchItemVal(...@@ -11754,7 +11728,7 @@ fn resolveSwitchItemVal(
11754 return val.toIntern();11728 return val.toIntern();
11755 } else |err| switch (err) {11729 } else |err| switch (err) {
11756 error.NeededSourceLocation => {11730 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);
11758 _ = try sema.resolveConstValue(block, src, item, "switch prong values must be comptime-known");11732 _ = try sema.resolveConstValue(block, src, item, "switch prong values must be comptime-known");
11759 unreachable;11733 unreachable;
11760 },11734 },
...@@ -11827,7 +11801,7 @@ fn validateSwitchItemError(...@@ -11827,7 +11801,7 @@ fn validateSwitchItemError(
11827 const ip = &sema.mod.intern_pool;11801 const ip = &sema.mod.intern_pool;
11828 const item = try sema.resolveSwitchItemVal(block, item_ref, src_node_offset, switch_prong_src, .none);11802 const item = try sema.resolveSwitchItemVal(block, item_ref, src_node_offset, switch_prong_src, .none);
11829 // TODO: Do i need to typecheck here?11803 // 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;
11831 const maybe_prev_src = if (try seen_errors.fetchPut(error_name, switch_prong_src)) |prev|11805 const maybe_prev_src = if (try seen_errors.fetchPut(error_name, switch_prong_src)) |prev|
11832 prev.value11806 prev.value
11833 else11807 else
...@@ -11844,7 +11818,7 @@ fn validateSwitchDupe(...@@ -11844,7 +11818,7 @@ fn validateSwitchDupe(
11844) CompileError!void {11818) CompileError!void {
11845 const prev_prong_src = maybe_prev_src orelse return;11819 const prev_prong_src = maybe_prev_src orelse return;
11846 const mod = sema.mod;11820 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);
11848 const src = switch_prong_src.resolve(mod, block_src_decl, src_node_offset, .none);11822 const src = switch_prong_src.resolve(mod, block_src_decl, src_node_offset, .none);
11849 const prev_src = prev_prong_src.resolve(mod, block_src_decl, src_node_offset, .none);11823 const prev_src = prev_prong_src.resolve(mod, block_src_decl, src_node_offset, .none);
11850 const msg = msg: {11824 const msg = msg: {
...@@ -11884,7 +11858,7 @@ fn validateSwitchItemBool(...@@ -11884,7 +11858,7 @@ fn validateSwitchItemBool(
11884 false_count.* += 1;11858 false_count.* += 1;
11885 }11859 }
11886 if (true_count.* + false_count.* > 2) {11860 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);
11888 const src = switch_prong_src.resolve(mod, block_src_decl, src_node_offset, .none);11862 const src = switch_prong_src.resolve(mod, block_src_decl, src_node_offset, .none);
11889 return sema.fail(block, src, "duplicate switch value", .{});11863 return sema.fail(block, src, "duplicate switch value", .{});
11890 }11864 }
...@@ -12020,7 +11994,7 @@ fn maybeErrorUnwrapCondbr(sema: *Sema, block: *Block, body: []const Zir.Inst.Ind...@@ -12020,7 +11994,7 @@ fn maybeErrorUnwrapCondbr(sema: *Sema, block: *Block, body: []const Zir.Inst.Ind
12020 }11994 }
12021 if (try sema.resolveDefinedValue(block, cond_src, err_operand)) |val| {11995 if (try sema.resolveDefinedValue(block, cond_src, err_operand)) |val| {
12022 if (!operand_ty.isError(mod)) return;11996 if (!operand_ty.isError(mod)) return;
12023 if (val.getError(mod) == null) return;11997 if (val.getErrorName(mod) == .none) return;
12024 try sema.maybeErrorUnwrapComptime(block, body, err_operand);11998 try sema.maybeErrorUnwrapComptime(block, body, err_operand);
12025 }11999 }
12026}12000}
...@@ -12042,8 +12016,8 @@ fn maybeErrorUnwrapComptime(sema: *Sema, block: *Block, body: []const Zir.Inst.I...@@ -12042,8 +12016,8 @@ fn maybeErrorUnwrapComptime(sema: *Sema, block: *Block, body: []const Zir.Inst.I
12042 const src = inst_data.src();12016 const src = inst_data.src();
1204312017
12044 if (try sema.resolveDefinedValue(block, src, operand)) |val| {12018 if (try sema.resolveDefinedValue(block, src, operand)) |val| {
12045 if (val.getError(sema.mod)) |name| {12019 if (val.getErrorName(sema.mod).unwrap()) |name| {
12046 return sema.fail(block, src, "caught unexpected error '{s}'", .{name});12020 return sema.fail(block, src, "caught unexpected error '{}'", .{name.fmt(&sema.mod.intern_pool)});
12047 }12021 }
12048 }12022 }
12049}12023}
...@@ -12073,7 +12047,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -12073,7 +12047,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
12073 if (anon_struct.names.len != 0) {12047 if (anon_struct.names.len != 0) {
12074 break :hf mem.indexOfScalar(InternPool.NullTerminatedString, anon_struct.names, field_name) != null;12048 break :hf mem.indexOfScalar(InternPool.NullTerminatedString, anon_struct.names, field_name) != null;
12075 } else {12049 } 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;
12077 break :hf field_index < ty.structFieldCount(mod);12051 break :hf field_index < ty.structFieldCount(mod);
12078 }12052 }
12079 },12053 },
...@@ -12094,7 +12068,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -12094,7 +12068,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
12094 else => {},12068 else => {},
12095 }12069 }
12096 return sema.fail(block, ty_src, "type '{}' does not support '@hasField'", .{12070 return sema.fail(block, ty_src, "type '{}' does not support '@hasField'", .{
12097 ty.fmt(sema.mod),12071 ty.fmt(mod),
12098 });12072 });
12099 };12073 };
12100 if (has_field) {12074 if (has_field) {
...@@ -12209,7 +12183,7 @@ fn zirRetErrValueCode(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.R...@@ -12209,7 +12183,7 @@ fn zirRetErrValueCode(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.R
12209 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;12183 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;
12210 const name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code));12184 const name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code));
12211 _ = try mod.getErrorValue(name);12185 _ = try mod.getErrorValue(name);
12212 const error_set_type = try mod.singleErrorSetTypeNts(name);12186 const error_set_type = try mod.singleErrorSetType(name);
12213 return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{12187 return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{
12214 .ty = error_set_type.toIntern(),12188 .ty = error_set_type.toIntern(),
12215 .name = name,12189 .name = name,
...@@ -12260,36 +12234,36 @@ fn zirShl(...@@ -12260,36 +12234,36 @@ fn zirShl(
12260 if (rhs_ty.zigTypeTag(mod) == .Vector) {12234 if (rhs_ty.zigTypeTag(mod) == .Vector) {
12261 var i: usize = 0;12235 var i: usize = 0;
12262 while (i < rhs_ty.vectorLen(mod)) : (i += 1) {12236 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);
12264 if (rhs_elem.compareHetero(.gte, bit_value, mod)) {12238 if (rhs_elem.compareHetero(.gte, bit_value, mod)) {
12265 return sema.fail(block, rhs_src, "shift amount '{}' at index '{d}' is too large for operand type '{}'", .{12239 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),
12267 i,12241 i,
12268 scalar_ty.fmt(sema.mod),12242 scalar_ty.fmt(mod),
12269 });12243 });
12270 }12244 }
12271 }12245 }
12272 } else if (rhs_val.compareHetero(.gte, bit_value, mod)) {12246 } else if (rhs_val.compareHetero(.gte, bit_value, mod)) {
12273 return sema.fail(block, rhs_src, "shift amount '{}' is too large for operand type '{}'", .{12247 return sema.fail(block, rhs_src, "shift amount '{}' is too large for operand type '{}'", .{
12274 rhs_val.fmtValue(scalar_ty, sema.mod),12248 rhs_val.fmtValue(scalar_ty, mod),
12275 scalar_ty.fmt(sema.mod),12249 scalar_ty.fmt(mod),
12276 });12250 });
12277 }12251 }
12278 }12252 }
12279 if (rhs_ty.zigTypeTag(mod) == .Vector) {12253 if (rhs_ty.zigTypeTag(mod) == .Vector) {
12280 var i: usize = 0;12254 var i: usize = 0;
12281 while (i < rhs_ty.vectorLen(mod)) : (i += 1) {12255 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);
12283 if (rhs_elem.compareHetero(.lt, try mod.intValue(scalar_rhs_ty, 0), mod)) {12257 if (rhs_elem.compareHetero(.lt, try mod.intValue(scalar_rhs_ty, 0), mod)) {
12284 return sema.fail(block, rhs_src, "shift by negative amount '{}' at index '{d}'", .{12258 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),
12286 i,12260 i,
12287 });12261 });
12288 }12262 }
12289 }12263 }
12290 } else if (rhs_val.compareHetero(.lt, try mod.intValue(rhs_ty, 0), mod)) {12264 } else if (rhs_val.compareHetero(.lt, try mod.intValue(rhs_ty, 0), mod)) {
12291 return sema.fail(block, rhs_src, "shift by negative amount '{}'", .{12265 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),
12293 });12267 });
12294 }12268 }
12295 }12269 }
...@@ -12305,25 +12279,25 @@ fn zirShl(...@@ -12305,25 +12279,25 @@ fn zirShl(
1230512279
12306 const val = switch (air_tag) {12280 const val = switch (air_tag) {
12307 .shl_exact => val: {12281 .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);
12309 if (scalar_ty.zigTypeTag(mod) == .ComptimeInt) {12283 if (scalar_ty.zigTypeTag(mod) == .ComptimeInt) {
12310 break :val shifted.wrapped_result;12284 break :val shifted.wrapped_result;
12311 }12285 }
12312 if (shifted.overflow_bit.compareAllWithZero(.eq, sema.mod)) {12286 if (shifted.overflow_bit.compareAllWithZero(.eq, mod)) {
12313 break :val shifted.wrapped_result;12287 break :val shifted.wrapped_result;
12314 }12288 }
12315 return sema.fail(block, src, "operation caused overflow", .{});12289 return sema.fail(block, src, "operation caused overflow", .{});
12316 },12290 },
1231712291
12318 .shl_sat => if (scalar_ty.zigTypeTag(mod) == .ComptimeInt)12292 .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)
12320 else12294 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
12323 .shl => if (scalar_ty.zigTypeTag(mod) == .ComptimeInt)12297 .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)
12325 else12299 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
12328 else => unreachable,12302 else => unreachable,
12329 };12303 };
...@@ -12441,36 +12415,36 @@ fn zirShr(...@@ -12441,36 +12415,36 @@ fn zirShr(
12441 if (rhs_ty.zigTypeTag(mod) == .Vector) {12415 if (rhs_ty.zigTypeTag(mod) == .Vector) {
12442 var i: usize = 0;12416 var i: usize = 0;
12443 while (i < rhs_ty.vectorLen(mod)) : (i += 1) {12417 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);
12445 if (rhs_elem.compareHetero(.gte, bit_value, mod)) {12419 if (rhs_elem.compareHetero(.gte, bit_value, mod)) {
12446 return sema.fail(block, rhs_src, "shift amount '{}' at index '{d}' is too large for operand type '{}'", .{12420 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),
12448 i,12422 i,
12449 scalar_ty.fmt(sema.mod),12423 scalar_ty.fmt(mod),
12450 });12424 });
12451 }12425 }
12452 }12426 }
12453 } else if (rhs_val.compareHetero(.gte, bit_value, mod)) {12427 } else if (rhs_val.compareHetero(.gte, bit_value, mod)) {
12454 return sema.fail(block, rhs_src, "shift amount '{}' is too large for operand type '{}'", .{12428 return sema.fail(block, rhs_src, "shift amount '{}' is too large for operand type '{}'", .{
12455 rhs_val.fmtValue(scalar_ty, sema.mod),12429 rhs_val.fmtValue(scalar_ty, mod),
12456 scalar_ty.fmt(sema.mod),12430 scalar_ty.fmt(mod),
12457 });12431 });
12458 }12432 }
12459 }12433 }
12460 if (rhs_ty.zigTypeTag(mod) == .Vector) {12434 if (rhs_ty.zigTypeTag(mod) == .Vector) {
12461 var i: usize = 0;12435 var i: usize = 0;
12462 while (i < rhs_ty.vectorLen(mod)) : (i += 1) {12436 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);
12464 if (rhs_elem.compareHetero(.lt, try mod.intValue(rhs_ty.childType(mod), 0), mod)) {12438 if (rhs_elem.compareHetero(.lt, try mod.intValue(rhs_ty.childType(mod), 0), mod)) {
12465 return sema.fail(block, rhs_src, "shift by negative amount '{}' at index '{d}'", .{12439 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),
12467 i,12441 i,
12468 });12442 });
12469 }12443 }
12470 }12444 }
12471 } else if (rhs_val.compareHetero(.lt, try mod.intValue(rhs_ty, 0), mod)) {12445 } else if (rhs_val.compareHetero(.lt, try mod.intValue(rhs_ty, 0), mod)) {
12472 return sema.fail(block, rhs_src, "shift by negative amount '{}'", .{12446 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),
12474 });12448 });
12475 }12449 }
12476 if (maybe_lhs_val) |lhs_val| {12450 if (maybe_lhs_val) |lhs_val| {
...@@ -12479,12 +12453,12 @@ fn zirShr(...@@ -12479,12 +12453,12 @@ fn zirShr(
12479 }12453 }
12480 if (air_tag == .shr_exact) {12454 if (air_tag == .shr_exact) {
12481 // Detect if any ones would be shifted out.12455 // 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);
12483 if (!(try truncated.compareAllWithZeroAdvanced(.eq, sema))) {12457 if (!(try truncated.compareAllWithZeroAdvanced(.eq, sema))) {
12484 return sema.fail(block, src, "exact shift shifted out 1 bits", .{});12458 return sema.fail(block, src, "exact shift shifted out 1 bits", .{});
12485 }12459 }
12486 }12460 }
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);
12488 return sema.addConstant(lhs_ty, val);12462 return sema.addConstant(lhs_ty, val);
12489 } else {12463 } else {
12490 break :rs lhs_src;12464 break :rs lhs_src;
...@@ -12580,9 +12554,9 @@ fn zirBitwise(...@@ -12580,9 +12554,9 @@ fn zirBitwise(
12580 if (try sema.resolveMaybeUndefValIntable(casted_lhs)) |lhs_val| {12554 if (try sema.resolveMaybeUndefValIntable(casted_lhs)) |lhs_val| {
12581 if (try sema.resolveMaybeUndefValIntable(casted_rhs)) |rhs_val| {12555 if (try sema.resolveMaybeUndefValIntable(casted_rhs)) |rhs_val| {
12582 const result_val = switch (air_tag) {12556 const result_val = switch (air_tag) {
12583 .bit_and => try lhs_val.bitwiseAnd(rhs_val, resolved_type, sema.arena, sema.mod),12557 .bit_and => try lhs_val.bitwiseAnd(rhs_val, resolved_type, sema.arena, mod),
12584 .bit_or => try lhs_val.bitwiseOr(rhs_val, resolved_type, sema.arena, sema.mod),12558 .bit_or => try lhs_val.bitwiseOr(rhs_val, resolved_type, sema.arena, mod),
12585 .xor => try lhs_val.bitwiseXor(rhs_val, resolved_type, sema.arena, sema.mod),12559 .xor => try lhs_val.bitwiseXor(rhs_val, resolved_type, sema.arena, mod),
12586 else => unreachable,12560 else => unreachable,
12587 };12561 };
12588 return sema.addConstant(resolved_type, result_val);12562 return sema.addConstant(resolved_type, result_val);
...@@ -12613,7 +12587,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -12613,7 +12587,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1261312587
12614 if (scalar_type.zigTypeTag(mod) != .Int) {12588 if (scalar_type.zigTypeTag(mod) != .Int) {
12615 return sema.fail(block, src, "unable to perform binary not operation on type '{}'", .{12589 return sema.fail(block, src, "unable to perform binary not operation on type '{}'", .{
12616 operand_type.fmt(sema.mod),12590 operand_type.fmt(mod),
12617 });12591 });
12618 }12592 }
1261912593
...@@ -12624,15 +12598,15 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -12624,15 +12598,15 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
12624 const vec_len = try sema.usizeCast(block, operand_src, operand_type.vectorLen(mod));12598 const vec_len = try sema.usizeCast(block, operand_src, operand_type.vectorLen(mod));
12625 const elems = try sema.arena.alloc(InternPool.Index, vec_len);12599 const elems = try sema.arena.alloc(InternPool.Index, vec_len);
12626 for (elems, 0..) |*elem, i| {12600 for (elems, 0..) |*elem, i| {
12627 const elem_val = try val.elemValue(sema.mod, i);12601 const elem_val = try val.elemValue(mod, i);
12628 elem.* = try (try elem_val.bitwiseNot(scalar_type, sema.arena, sema.mod)).intern(scalar_type, mod);12602 elem.* = try (try elem_val.bitwiseNot(scalar_type, sema.arena, mod)).intern(scalar_type, mod);
12629 }12603 }
12630 return sema.addConstant(operand_type, (try mod.intern(.{ .aggregate = .{12604 return sema.addConstant(operand_type, (try mod.intern(.{ .aggregate = .{
12631 .ty = operand_type.toIntern(),12605 .ty = operand_type.toIntern(),
12632 .storage = .{ .elems = elems },12606 .storage = .{ .elems = elems },
12633 } })).toValue());12607 } })).toValue());
12634 } else {12608 } 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);
12636 return sema.addConstant(operand_type, result_val);12610 return sema.addConstant(operand_type, result_val);
12637 }12611 }
12638 }12612 }
...@@ -12949,7 +12923,7 @@ fn getArrayCatInfo(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Ins...@@ -12949,7 +12923,7 @@ fn getArrayCatInfo(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Ins
12949 return Type.ArrayInfo{12923 return Type.ArrayInfo{
12950 .elem_type = ptr_info.pointee_type,12924 .elem_type = ptr_info.pointee_type,
12951 .sentinel = ptr_info.sentinel,12925 .sentinel = ptr_info.sentinel,
12952 .len = val.sliceLen(sema.mod),12926 .len = val.sliceLen(mod),
12953 };12927 };
12954 },12928 },
12955 .One => {12929 .One => {
...@@ -13195,14 +13169,14 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -13195,14 +13169,14 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
13195 .Int, .ComptimeInt, .Float, .ComptimeFloat => false,13169 .Int, .ComptimeInt, .Float, .ComptimeFloat => false,
13196 else => true,13170 else => true,
13197 }) {13171 }) {
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)});
13199 }13173 }
1320013174
13201 if (rhs_scalar_ty.isAnyFloat()) {13175 if (rhs_scalar_ty.isAnyFloat()) {
13202 // We handle float negation here to ensure negative zero is represented in the bits.13176 // We handle float negation here to ensure negative zero is represented in the bits.
13203 if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| {13177 if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| {
13204 if (rhs_val.isUndef(mod)) return sema.addConstUndef(rhs_ty);13178 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));
13206 }13180 }
13207 try sema.requireRuntimeBlock(block, src, null);13181 try sema.requireRuntimeBlock(block, src, null);
13208 return block.addUnOp(if (block.float_mode == .Optimized) .neg_optimized else .neg, rhs);13182 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!...@@ -13225,7 +13199,7 @@ fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1322513199
13226 switch (rhs_scalar_ty.zigTypeTag(mod)) {13200 switch (rhs_scalar_ty.zigTypeTag(mod)) {
13227 .Int, .ComptimeInt, .Float, .ComptimeFloat => {},13201 .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)}),
13229 }13203 }
1323013204
13231 const lhs = try sema.addConstant(rhs_ty, try sema.splat(rhs_ty, try mod.intValue(rhs_scalar_ty, 0)));13205 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(...@@ -14099,8 +14073,8 @@ fn intRem(
14099 const result_data = try sema.arena.alloc(InternPool.Index, ty.vectorLen(mod));14073 const result_data = try sema.arena.alloc(InternPool.Index, ty.vectorLen(mod));
14100 const scalar_ty = ty.scalarType(mod);14074 const scalar_ty = ty.scalarType(mod);
14101 for (result_data, 0..) |*scalar, i| {14075 for (result_data, 0..) |*scalar, i| {
14102 const lhs_elem = try lhs.elemValue(sema.mod, i);14076 const lhs_elem = try lhs.elemValue(mod, i);
14103 const rhs_elem = try rhs.elemValue(sema.mod, i);14077 const rhs_elem = try rhs.elemValue(mod, i);
14104 scalar.* = try (try sema.intRemScalar(lhs_elem, rhs_elem, scalar_ty)).intern(scalar_ty, mod);14078 scalar.* = try (try sema.intRemScalar(lhs_elem, rhs_elem, scalar_ty)).intern(scalar_ty, mod);
14105 }14079 }
14106 return (try mod.intern(.{ .aggregate = .{14080 return (try mod.intern(.{ .aggregate = .{
...@@ -14499,7 +14473,7 @@ fn zirOverflowArithmetic(...@@ -14499,7 +14473,7 @@ fn zirOverflowArithmetic(
14499 break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef };14473 break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef };
14500 }14474 }
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);
14503 break :result .{ .overflow_bit = result.overflow_bit, .wrapped = result.wrapped_result };14477 break :result .{ .overflow_bit = result.overflow_bit, .wrapped = result.wrapped_result };
14504 }14478 }
14505 }14479 }
...@@ -14917,7 +14891,7 @@ fn analyzeArithmetic(...@@ -14917,7 +14891,7 @@ fn analyzeArithmetic(
14917 }14891 }
14918 if (is_int) {14892 if (is_int) {
14919 var overflow_idx: ?usize = null;14893 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);
14921 if (overflow_idx) |vec_idx| {14895 if (overflow_idx) |vec_idx| {
14922 return sema.failWithIntegerOverflow(block, src, resolved_type, product, vec_idx);14896 return sema.failWithIntegerOverflow(block, src, resolved_type, product, vec_idx);
14923 }14897 }
...@@ -14925,7 +14899,7 @@ fn analyzeArithmetic(...@@ -14925,7 +14899,7 @@ fn analyzeArithmetic(
14925 } else {14899 } else {
14926 return sema.addConstant(14900 return sema.addConstant(
14927 resolved_type,14901 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),
14929 );14903 );
14930 }14904 }
14931 } else break :rs .{ .src = lhs_src, .air_tag = air_tag };14905 } else break :rs .{ .src = lhs_src, .air_tag = air_tag };
...@@ -14975,7 +14949,7 @@ fn analyzeArithmetic(...@@ -14975,7 +14949,7 @@ fn analyzeArithmetic(
14975 }14949 }
14976 return sema.addConstant(14950 return sema.addConstant(
14977 resolved_type,14951 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),
14979 );14953 );
14980 } else break :rs .{ .src = lhs_src, .air_tag = air_tag };14954 } else break :rs .{ .src = lhs_src, .air_tag = air_tag };
14981 } else break :rs .{ .src = rhs_src, .air_tag = air_tag };14955 } else break :rs .{ .src = rhs_src, .air_tag = air_tag };
...@@ -15023,9 +14997,9 @@ fn analyzeArithmetic(...@@ -15023,9 +14997,9 @@ fn analyzeArithmetic(
15023 }14997 }
1502414998
15025 const val = if (scalar_tag == .ComptimeInt)14999 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)
15027 else15001 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
15030 return sema.addConstant(resolved_type, val);15004 return sema.addConstant(resolved_type, val);
15031 } else break :rs .{ .src = lhs_src, .air_tag = .mul_sat };15005 } else break :rs .{ .src = lhs_src, .air_tag = .mul_sat };
...@@ -15118,7 +15092,7 @@ fn analyzePtrArithmetic(...@@ -15118,7 +15092,7 @@ fn analyzePtrArithmetic(
15118 // non zero).15092 // non zero).
15119 const new_align = @as(u32, 1) << @intCast(u5, @ctz(addend | ptr_info.@"align"));15093 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, .{
15122 .pointee_type = ptr_info.pointee_type,15096 .pointee_type = ptr_info.pointee_type,
15123 .sentinel = ptr_info.sentinel,15097 .sentinel = ptr_info.sentinel,
15124 .@"align" = new_align,15098 .@"align" = new_align,
...@@ -15150,7 +15124,7 @@ fn analyzePtrArithmetic(...@@ -15150,7 +15124,7 @@ fn analyzePtrArithmetic(
15150 if (air_tag == .ptr_sub) {15124 if (air_tag == .ptr_sub) {
15151 return sema.fail(block, op_src, "TODO implement Sema comptime pointer subtraction", .{});15125 return sema.fail(block, op_src, "TODO implement Sema comptime pointer subtraction", .{});
15152 }15126 }
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);
15154 return sema.addConstant(new_ptr_ty, new_ptr_val);15128 return sema.addConstant(new_ptr_ty, new_ptr_val);
15155 } else break :rs offset_src;15129 } else break :rs offset_src;
15156 } else break :rs ptr_src;15130 } else break :rs ptr_src;
...@@ -15382,7 +15356,7 @@ fn zirCmpEq(...@@ -15382,7 +15356,7 @@ fn zirCmpEq(
1538215356
15383 if (lhs_ty_tag == .Null or rhs_ty_tag == .Null) {15357 if (lhs_ty_tag == .Null or rhs_ty_tag == .Null) {
15384 const non_null_type = if (lhs_ty_tag == .Null) rhs_ty else lhs_ty;15358 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)});
15386 }15360 }
1538715361
15388 if (lhs_ty_tag == .Union and (rhs_ty_tag == .EnumLiteral or rhs_ty_tag == .Enum)) {15362 if (lhs_ty_tag == .Union and (rhs_ty_tag == .EnumLiteral or rhs_ty_tag == .Enum)) {
...@@ -15419,7 +15393,7 @@ fn zirCmpEq(...@@ -15419,7 +15393,7 @@ fn zirCmpEq(
15419 if (lhs_ty_tag == .Type and rhs_ty_tag == .Type) {15393 if (lhs_ty_tag == .Type and rhs_ty_tag == .Type) {
15420 const lhs_as_type = try sema.analyzeAsType(block, lhs_src, lhs);15394 const lhs_as_type = try sema.analyzeAsType(block, lhs_src, lhs);
15421 const rhs_as_type = try sema.analyzeAsType(block, rhs_src, rhs);15395 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)) {
15423 return Air.Inst.Ref.bool_true;15397 return Air.Inst.Ref.bool_true;
15424 } else {15398 } else {
15425 return Air.Inst.Ref.bool_false;15399 return Air.Inst.Ref.bool_false;
...@@ -15444,7 +15418,7 @@ fn analyzeCmpUnionTag(...@@ -15444,7 +15418,7 @@ fn analyzeCmpUnionTag(
15444 const msg = msg: {15418 const msg = msg: {
15445 const msg = try sema.errMsg(block, un_src, "comparison of union and enum literal is only valid for tagged union types", .{});15419 const msg = try sema.errMsg(block, un_src, "comparison of union and enum literal is only valid for tagged union types", .{});
15446 errdefer msg.destroy(sema.gpa);15420 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)});
15448 break :msg msg;15422 break :msg msg;
15449 };15423 };
15450 return sema.failWithOwnedErrorMsg(msg);15424 return sema.failWithOwnedErrorMsg(msg);
...@@ -15456,7 +15430,7 @@ fn analyzeCmpUnionTag(...@@ -15456,7 +15430,7 @@ fn analyzeCmpUnionTag(
1545615430
15457 if (try sema.resolveMaybeUndefVal(coerced_tag)) |enum_val| {15431 if (try sema.resolveMaybeUndefVal(coerced_tag)) |enum_val| {
15458 if (enum_val.isUndef(mod)) return sema.addConstUndef(Type.bool);15432 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);
15460 if (field_ty.zigTypeTag(mod) == .NoReturn) {15434 if (field_ty.zigTypeTag(mod) == .NoReturn) {
15461 return Air.Inst.Ref.bool_false;15435 return Air.Inst.Ref.bool_false;
15462 }15436 }
...@@ -15524,7 +15498,7 @@ fn analyzeCmp(...@@ -15524,7 +15498,7 @@ fn analyzeCmp(
15524 const resolved_type = try sema.resolvePeerTypes(block, src, instructions, .{ .override = &[_]?LazySrcLoc{ lhs_src, rhs_src } });15498 const resolved_type = try sema.resolvePeerTypes(block, src, instructions, .{ .override = &[_]?LazySrcLoc{ lhs_src, rhs_src } });
15525 if (!resolved_type.isSelfComparable(mod, is_equality_cmp)) {15499 if (!resolved_type.isSelfComparable(mod, is_equality_cmp)) {
15526 return sema.fail(block, src, "operator {s} not allowed for type '{}'", .{15500 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),
15528 });15502 });
15529 }15503 }
15530 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);15504 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....@@ -15634,7 +15608,7 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
15634 .Undefined,15608 .Undefined,
15635 .Null,15609 .Null,
15636 .Opaque,15610 .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
15639 .Type,15613 .Type,
15640 .EnumLiteral,15614 .EnumLiteral,
...@@ -15677,7 +15651,7 @@ fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -15677,7 +15651,7 @@ fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
15677 .Undefined,15651 .Undefined,
15678 .Null,15652 .Null,
15679 .Opaque,15653 .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
15682 .Type,15656 .Type,
15683 .EnumLiteral,15657 .EnumLiteral,
...@@ -17163,7 +17137,7 @@ fn log2IntType(sema: *Sema, block: *Block, operand: Type, src: LazySrcLoc) Compi...@@ -17163,7 +17137,7 @@ fn log2IntType(sema: *Sema, block: *Block, operand: Type, src: LazySrcLoc) Compi
17163 block,17137 block,
17164 src,17138 src,
17165 "bit shifting operation expected integer type, found '{}'",17139 "bit shifting operation expected integer type, found '{}'",
17166 .{operand.fmt(sema.mod)},17140 .{operand.fmt(mod)},
17167 );17141 );
17168}17142}
1716917143
...@@ -17395,7 +17369,7 @@ fn checkErrorType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {...@@ -17395,7 +17369,7 @@ fn checkErrorType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {
17395 switch (ty.zigTypeTag(mod)) {17369 switch (ty.zigTypeTag(mod)) {
17396 .ErrorSet, .ErrorUnion, .Undefined => return,17370 .ErrorSet, .ErrorUnion, .Undefined => return,
17397 else => return sema.fail(block, src, "expected error union type, found '{}'", .{17371 else => return sema.fail(block, src, "expected error union type, found '{}'", .{
17398 ty.fmt(sema.mod),17372 ty.fmt(mod),
17399 }),17373 }),
17400 }17374 }
17401}17375}
...@@ -17521,7 +17495,7 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -17521,7 +17495,7 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!
17521 const mod = sema.mod;17495 const mod = sema.mod;
17522 if (err_union_ty.zigTypeTag(mod) != .ErrorUnion) {17496 if (err_union_ty.zigTypeTag(mod) != .ErrorUnion) {
17523 return sema.fail(parent_block, operand_src, "expected error union type, found '{}'", .{17497 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),
17525 });17499 });
17526 }17500 }
17527 const is_non_err = try sema.analyzeIsNonErrComptimeOnly(parent_block, operand_src, err_union);17501 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...@@ -17568,7 +17542,7 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr
17568 const mod = sema.mod;17542 const mod = sema.mod;
17569 if (err_union_ty.zigTypeTag(mod) != .ErrorUnion) {17543 if (err_union_ty.zigTypeTag(mod) != .ErrorUnion) {
17570 return sema.fail(parent_block, operand_src, "expected error union type, found '{}'", .{17544 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),
17572 });17546 });
17573 }17547 }
17574 const is_non_err = try sema.analyzeIsNonErrComptimeOnly(parent_block, operand_src, err_union);17548 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...@@ -17590,7 +17564,7 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr
1759017564
17591 const operand_ty = sema.typeOf(operand);17565 const operand_ty = sema.typeOf(operand);
17592 const ptr_info = operand_ty.ptrInfo(mod);17566 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, .{
17594 .pointee_type = err_union_ty.errorUnionPayload(mod),17568 .pointee_type = err_union_ty.errorUnionPayload(mod),
17595 .@"addrspace" = ptr_info.@"addrspace",17569 .@"addrspace" = ptr_info.@"addrspace",
17596 .mutable = ptr_info.mutable,17570 .mutable = ptr_info.mutable,
...@@ -17693,7 +17667,7 @@ fn zirRetErrValue(...@@ -17693,7 +17667,7 @@ fn zirRetErrValue(
17693 _ = try mod.getErrorValue(err_name);17667 _ = try mod.getErrorValue(err_name);
17694 const src = inst_data.src();17668 const src = inst_data.src();
17695 // Return the error code from the function.17669 // 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);
17697 const result_inst = try sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{17671 const result_inst = try sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{
17698 .ty = error_set_type.toIntern(),17672 .ty = error_set_type.toIntern(),
17699 .name = err_name,17673 .name = err_name,
...@@ -18003,7 +17977,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -18003,7 +17977,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
18003 if (elem_ty.zigTypeTag(mod) == .NoReturn)17977 if (elem_ty.zigTypeTag(mod) == .NoReturn)
18004 return sema.fail(block, elem_ty_src, "pointer to noreturn not allowed", .{});17978 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
18008 var extra_i = extra.end;17982 var extra_i = extra.end;
1800917983
...@@ -18073,10 +18047,10 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -18073,10 +18047,10 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
18073 } else if (inst_data.size == .C) {18047 } else if (inst_data.size == .C) {
18074 if (!try sema.validateExternType(elem_ty, .other)) {18048 if (!try sema.validateExternType(elem_ty, .other)) {
18075 const msg = msg: {18049 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)});
18077 errdefer msg.destroy(sema.gpa);18051 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);
18080 try sema.explainWhyTypeIsNotExtern(msg, elem_ty_src.toSrcLoc(src_decl, mod), elem_ty, .other);18054 try sema.explainWhyTypeIsNotExtern(msg, elem_ty_src.toSrcLoc(src_decl, mod), elem_ty, .other);
1808118055
18082 try sema.addDeclaredHereNote(msg, elem_ty);18056 try sema.addDeclaredHereNote(msg, elem_ty);
...@@ -18273,7 +18247,7 @@ fn zirStructInit(...@@ -18273,7 +18247,7 @@ fn zirStructInit(
18273 return sema.failWithNeededComptime(block, field_src, "value stored in comptime field must be comptime-known");18247 return sema.failWithNeededComptime(block, field_src, "value stored in comptime field must be comptime-known");
18274 };18248 };
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)) {
18277 return sema.failWithInvalidComptimeFieldStore(block, field_src, resolved_ty, field_index);18251 return sema.failWithInvalidComptimeFieldStore(block, field_src, resolved_ty, field_index);
18278 }18252 }
18279 };18253 };
...@@ -18307,8 +18281,8 @@ fn zirStructInit(...@@ -18307,8 +18281,8 @@ fn zirStructInit(
18307 }18281 }
1830818282
18309 if (is_ref) {18283 if (is_ref) {
18310 const target = sema.mod.getTarget();18284 const target = mod.getTarget();
18311 const alloc_ty = try Type.ptr(sema.arena, sema.mod, .{18285 const alloc_ty = try Type.ptr(sema.arena, mod, .{
18312 .pointee_type = resolved_ty,18286 .pointee_type = resolved_ty,
18313 .@"addrspace" = target_util.defaultAddressSpace(target, .local),18287 .@"addrspace" = target_util.defaultAddressSpace(target, .local),
18314 });18288 });
...@@ -18359,8 +18333,8 @@ fn finishStructInit(...@@ -18359,8 +18333,8 @@ fn finishStructInit(
18359 }18333 }
18360 } else {18334 } else {
18361 const field_name = anon_struct.names[i];18335 const field_name = anon_struct.names[i];
18362 const template = "missing struct field: {s}";18336 const template = "missing struct field: {}";
18363 const args = .{ip.stringToSlice(field_name)};18337 const args = .{field_name.fmt(ip)};
18364 if (root_msg) |msg| {18338 if (root_msg) |msg| {
18365 try sema.errNote(block, init_src, msg, template, args);18339 try sema.errNote(block, init_src, msg, template, args);
18366 } else {18340 } else {
...@@ -18379,8 +18353,8 @@ fn finishStructInit(...@@ -18379,8 +18353,8 @@ fn finishStructInit(
1837918353
18380 if (field.default_val == .none) {18354 if (field.default_val == .none) {
18381 const field_name = struct_obj.fields.keys()[i];18355 const field_name = struct_obj.fields.keys()[i];
18382 const template = "missing struct field: {s}";18356 const template = "missing struct field: {}";
18383 const args = .{ip.stringToSlice(field_name)};18357 const args = .{field_name.fmt(ip)};
18384 if (root_msg) |msg| {18358 if (root_msg) |msg| {
18385 try sema.errNote(block, init_src, msg, template, args);18359 try sema.errNote(block, init_src, msg, template, args);
18386 } else {18360 } else {
...@@ -18396,12 +18370,12 @@ fn finishStructInit(...@@ -18396,12 +18370,12 @@ fn finishStructInit(
1839618370
18397 if (root_msg) |msg| {18371 if (root_msg) |msg| {
18398 if (mod.typeToStruct(struct_ty)) |struct_obj| {18372 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);
18400 try mod.errNoteNonLazy(18374 try mod.errNoteNonLazy(
18401 struct_obj.srcLoc(mod),18375 struct_obj.srcLoc(mod),
18402 msg,18376 msg,
18403 "struct '{s}' declared here",18377 "struct '{}' declared here",
18404 .{fqn},18378 .{fqn.fmt(ip)},
18405 );18379 );
18406 }18380 }
18407 root_msg = null;18381 root_msg = null;
...@@ -18431,7 +18405,7 @@ fn finishStructInit(...@@ -18431,7 +18405,7 @@ fn finishStructInit(
18431 if (is_ref) {18405 if (is_ref) {
18432 try sema.resolveStructLayout(struct_ty);18406 try sema.resolveStructLayout(struct_ty);
18433 const target = sema.mod.getTarget();18407 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, .{
18435 .pointee_type = struct_ty,18409 .pointee_type = struct_ty,
18436 .@"addrspace" = target_util.defaultAddressSpace(target, .local),18410 .@"addrspace" = target_util.defaultAddressSpace(target, .local),
18437 });18411 });
...@@ -18489,7 +18463,7 @@ fn zirStructInitAnon(...@@ -18489,7 +18463,7 @@ fn zirStructInitAnon(
18489 const gop = fields.getOrPutAssumeCapacity(name_ip);18463 const gop = fields.getOrPutAssumeCapacity(name_ip);
18490 if (gop.found_existing) {18464 if (gop.found_existing) {
18491 const msg = msg: {18465 const msg = msg: {
18492 const decl = sema.mod.declPtr(block.src_decl);18466 const decl = mod.declPtr(block.src_decl);
18493 const field_src = mod.initSrc(src.node_offset.x, decl, i);18467 const field_src = mod.initSrc(src.node_offset.x, decl, i);
18494 const msg = try sema.errMsg(block, field_src, "duplicate field", .{});18468 const msg = try sema.errMsg(block, field_src, "duplicate field", .{});
18495 errdefer msg.destroy(gpa);18469 errdefer msg.destroy(gpa);
...@@ -18506,7 +18480,7 @@ fn zirStructInitAnon(...@@ -18506,7 +18480,7 @@ fn zirStructInitAnon(
18506 field_ty.* = sema.typeOf(init).toIntern();18480 field_ty.* = sema.typeOf(init).toIntern();
18507 if (field_ty.toType().zigTypeTag(mod) == .Opaque) {18481 if (field_ty.toType().zigTypeTag(mod) == .Opaque) {
18508 const msg = msg: {18482 const msg = msg: {
18509 const decl = sema.mod.declPtr(block.src_decl);18483 const decl = mod.declPtr(block.src_decl);
18510 const field_src = mod.initSrc(src.node_offset.x, decl, i);18484 const field_src = mod.initSrc(src.node_offset.x, decl, i);
18511 const msg = try sema.errMsg(block, field_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});18485 const msg = try sema.errMsg(block, field_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
18512 errdefer msg.destroy(sema.gpa);18486 errdefer msg.destroy(sema.gpa);
...@@ -18542,7 +18516,7 @@ fn zirStructInitAnon(...@@ -18542,7 +18516,7 @@ fn zirStructInitAnon(
1854218516
18543 sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) {18517 sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) {
18544 error.NeededSourceLocation => {18518 error.NeededSourceLocation => {
18545 const decl = sema.mod.declPtr(block.src_decl);18519 const decl = mod.declPtr(block.src_decl);
18546 const field_src = mod.initSrc(src.node_offset.x, decl, runtime_index);18520 const field_src = mod.initSrc(src.node_offset.x, decl, runtime_index);
18547 try sema.requireRuntimeBlock(block, src, field_src);18521 try sema.requireRuntimeBlock(block, src, field_src);
18548 unreachable;18522 unreachable;
...@@ -18551,8 +18525,8 @@ fn zirStructInitAnon(...@@ -18551,8 +18525,8 @@ fn zirStructInitAnon(
18551 };18525 };
1855218526
18553 if (is_ref) {18527 if (is_ref) {
18554 const target = sema.mod.getTarget();18528 const target = mod.getTarget();
18555 const alloc_ty = try Type.ptr(sema.arena, sema.mod, .{18529 const alloc_ty = try Type.ptr(sema.arena, mod, .{
18556 .pointee_type = tuple_ty.toType(),18530 .pointee_type = tuple_ty.toType(),
18557 .@"addrspace" = target_util.defaultAddressSpace(target, .local),18531 .@"addrspace" = target_util.defaultAddressSpace(target, .local),
18558 });18532 });
...@@ -18563,7 +18537,7 @@ fn zirStructInitAnon(...@@ -18563,7 +18537,7 @@ fn zirStructInitAnon(
18563 const item = sema.code.extraData(Zir.Inst.StructInitAnon.Item, extra_index);18537 const item = sema.code.extraData(Zir.Inst.StructInitAnon.Item, extra_index);
18564 extra_index = item.end;18538 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, .{
18567 .mutable = true,18541 .mutable = true,
18568 .@"addrspace" = target_util.defaultAddressSpace(target, .local),18542 .@"addrspace" = target_util.defaultAddressSpace(target, .local),
18569 .pointee_type = field_ty.toType(),18543 .pointee_type = field_ty.toType(),
...@@ -18617,7 +18591,7 @@ fn zirArrayInit(...@@ -18617,7 +18591,7 @@ fn zirArrayInit(
18617 array_ty.elemType2(mod);18591 array_ty.elemType2(mod);
18618 resolved_args[i] = sema.coerce(block, elem_ty, resolved_arg, .unneeded) catch |err| switch (err) {18592 resolved_args[i] = sema.coerce(block, elem_ty, resolved_arg, .unneeded) catch |err| switch (err) {
18619 error.NeededSourceLocation => {18593 error.NeededSourceLocation => {
18620 const decl = sema.mod.declPtr(block.src_decl);18594 const decl = mod.declPtr(block.src_decl);
18621 const elem_src = mod.initSrc(src.node_offset.x, decl, i);18595 const elem_src = mod.initSrc(src.node_offset.x, decl, i);
18622 _ = try sema.coerce(block, elem_ty, resolved_arg, elem_src);18596 _ = try sema.coerce(block, elem_ty, resolved_arg, elem_src);
18623 unreachable;18597 unreachable;
...@@ -18653,7 +18627,7 @@ fn zirArrayInit(...@@ -18653,7 +18627,7 @@ fn zirArrayInit(
1865318627
18654 sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) {18628 sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) {
18655 error.NeededSourceLocation => {18629 error.NeededSourceLocation => {
18656 const decl = sema.mod.declPtr(block.src_decl);18630 const decl = mod.declPtr(block.src_decl);
18657 const elem_src = mod.initSrc(src.node_offset.x, decl, runtime_index);18631 const elem_src = mod.initSrc(src.node_offset.x, decl, runtime_index);
18658 try sema.requireRuntimeBlock(block, src, elem_src);18632 try sema.requireRuntimeBlock(block, src, elem_src);
18659 unreachable;18633 unreachable;
...@@ -18663,8 +18637,8 @@ fn zirArrayInit(...@@ -18663,8 +18637,8 @@ fn zirArrayInit(
18663 try sema.queueFullTypeResolution(array_ty);18637 try sema.queueFullTypeResolution(array_ty);
1866418638
18665 if (is_ref) {18639 if (is_ref) {
18666 const target = sema.mod.getTarget();18640 const target = mod.getTarget();
18667 const alloc_ty = try Type.ptr(sema.arena, sema.mod, .{18641 const alloc_ty = try Type.ptr(sema.arena, mod, .{
18668 .pointee_type = array_ty,18642 .pointee_type = array_ty,
18669 .@"addrspace" = target_util.defaultAddressSpace(target, .local),18643 .@"addrspace" = target_util.defaultAddressSpace(target, .local),
18670 });18644 });
...@@ -18672,7 +18646,7 @@ fn zirArrayInit(...@@ -18672,7 +18646,7 @@ fn zirArrayInit(
1867218646
18673 if (array_ty.isTuple(mod)) {18647 if (array_ty.isTuple(mod)) {
18674 for (resolved_args, 0..) |arg, i| {18648 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, .{
18676 .mutable = true,18650 .mutable = true,
18677 .@"addrspace" = target_util.defaultAddressSpace(target, .local),18651 .@"addrspace" = target_util.defaultAddressSpace(target, .local),
18678 .pointee_type = array_ty.structFieldType(i, mod),18652 .pointee_type = array_ty.structFieldType(i, mod),
...@@ -18686,7 +18660,7 @@ fn zirArrayInit(...@@ -18686,7 +18660,7 @@ fn zirArrayInit(
18686 return sema.makePtrConst(block, alloc);18660 return sema.makePtrConst(block, alloc);
18687 }18661 }
1868818662
18689 const elem_ptr_ty = try Type.ptr(sema.arena, sema.mod, .{18663 const elem_ptr_ty = try Type.ptr(sema.arena, mod, .{
18690 .mutable = true,18664 .mutable = true,
18691 .@"addrspace" = target_util.defaultAddressSpace(target, .local),18665 .@"addrspace" = target_util.defaultAddressSpace(target, .local),
18692 .pointee_type = array_ty.elemType2(mod),18666 .pointee_type = array_ty.elemType2(mod),
...@@ -18959,8 +18933,7 @@ fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -18959,8 +18933,7 @@ fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1895918933
18960 if (try sema.resolveDefinedValue(block, operand_src, operand)) |val| {18934 if (try sema.resolveDefinedValue(block, operand_src, operand)) |val| {
18961 const err_name = sema.mod.intern_pool.indexToKey(val.toIntern()).err.name;18935 const err_name = sema.mod.intern_pool.indexToKey(val.toIntern()).err.name;
18962 const bytes = sema.mod.intern_pool.stringToSlice(err_name);18936 return sema.addStrLit(block, sema.mod.intern_pool.stringToSlice(err_name));
18963 return sema.addStrLit(block, bytes);
18964 }18937 }
1896518938
18966 // Similar to zirTagName, we have special AIR instruction for the error name in case an optimimzation pass18939 // 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...@@ -19051,8 +19024,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
19051 .EnumLiteral => {19024 .EnumLiteral => {
19052 const val = try sema.resolveConstValue(block, .unneeded, operand, "");19025 const val = try sema.resolveConstValue(block, .unneeded, operand, "");
19053 const tag_name = ip.indexToKey(val.toIntern()).enum_literal;19026 const tag_name = ip.indexToKey(val.toIntern()).enum_literal;
19054 const bytes = ip.stringToSlice(tag_name);19027 return sema.addStrLit(block, ip.stringToSlice(tag_name));
19055 return sema.addStrLit(block, bytes);
19056 },19028 },
19057 .Enum => operand_ty,19029 .Enum => operand_ty,
19058 .Union => operand_ty.unionTagType(mod) orelse {19030 .Union => operand_ty.unionTagType(mod) orelse {
...@@ -19083,8 +19055,8 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -19083,8 +19055,8 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
19083 const field_index = enum_ty.enumTagFieldIndex(val, mod) orelse {19055 const field_index = enum_ty.enumTagFieldIndex(val, mod) orelse {
19084 const enum_decl = mod.declPtr(enum_decl_index);19056 const enum_decl = mod.declPtr(enum_decl_index);
19085 const msg = msg: {19057 const msg = msg: {
19086 const msg = try sema.errMsg(block, src, "no field with value '{}' in enum '{s}'", .{19058 const msg = try sema.errMsg(block, src, "no field with value '{}' in enum '{}'", .{
19087 val.fmtValue(enum_ty, sema.mod), ip.stringToSlice(enum_decl.name),19059 val.fmtValue(enum_ty, sema.mod), enum_decl.name.fmt(ip),
19088 });19060 });
19089 errdefer msg.destroy(sema.gpa);19061 errdefer msg.destroy(sema.gpa);
19090 try mod.errNoteNonLazy(enum_decl.srcLoc(mod), msg, "declared here", .{});19062 try mod.errNoteNonLazy(enum_decl.srcLoc(mod), msg, "declared here", .{});
...@@ -19374,8 +19346,8 @@ fn zirReify(...@@ -19374,8 +19346,8 @@ fn zirReify(
19374 _ = try mod.getErrorValue(name);19346 _ = try mod.getErrorValue(name);
19375 const gop = names.getOrPutAssumeCapacity(name);19347 const gop = names.getOrPutAssumeCapacity(name);
19376 if (gop.found_existing) {19348 if (gop.found_existing) {
19377 return sema.fail(block, src, "duplicate error '{s}'", .{19349 return sema.fail(block, src, "duplicate error '{}'", .{
19378 ip.stringToSlice(name),19350 name.fmt(ip),
19379 });19351 });
19380 }19352 }
19381 }19353 }
...@@ -19487,8 +19459,8 @@ fn zirReify(...@@ -19487,8 +19459,8 @@ fn zirReify(
1948719459
19488 if (!try sema.intFitsInType(value_val, int_tag_ty, null)) {19460 if (!try sema.intFitsInType(value_val, int_tag_ty, null)) {
19489 // TODO: better source location19461 // TODO: better source location
19490 return sema.fail(block, src, "field '{s}' with enumeration value '{}' is too large for backing int type '{}'", .{19462 return sema.fail(block, src, "field '{}' with enumeration value '{}' is too large for backing int type '{}'", .{
19491 ip.stringToSlice(field_name),19463 field_name.fmt(ip),
19492 value_val.fmtValue(Type.comptime_int, mod),19464 value_val.fmtValue(Type.comptime_int, mod),
19493 int_tag_ty.fmt(mod),19465 int_tag_ty.fmt(mod),
19494 });19466 });
...@@ -19496,8 +19468,8 @@ fn zirReify(...@@ -19496,8 +19468,8 @@ fn zirReify(
1949619468
19497 if (try incomplete_enum.addFieldName(ip, gpa, field_name)) |other_index| {19469 if (try incomplete_enum.addFieldName(ip, gpa, field_name)) |other_index| {
19498 const msg = msg: {19470 const msg = msg: {
19499 const msg = try sema.errMsg(block, src, "duplicate enum field '{s}'", .{19471 const msg = try sema.errMsg(block, src, "duplicate enum field '{}'", .{
19500 ip.stringToSlice(field_name),19472 field_name.fmt(ip),
19501 });19473 });
19502 errdefer msg.destroy(gpa);19474 errdefer msg.destroy(gpa);
19503 _ = other_index; // TODO: this note is incorrect19475 _ = other_index; // TODO: this note is incorrect
...@@ -19690,7 +19662,10 @@ fn zirReify(...@@ -19690,7 +19662,10 @@ fn zirReify(
19690 const tag_info = ip.indexToKey(union_obj.tag_ty.toIntern()).enum_type;19662 const tag_info = ip.indexToKey(union_obj.tag_ty.toIntern()).enum_type;
19691 const enum_index = tag_info.nameIndex(ip, field_name) orelse {19663 const enum_index = tag_info.nameIndex(ip, field_name) orelse {
19692 const msg = msg: {19664 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 });
19694 errdefer msg.destroy(gpa);19669 errdefer msg.destroy(gpa);
19695 try sema.addDeclaredHereNote(msg, union_obj.tag_ty);19670 try sema.addDeclaredHereNote(msg, union_obj.tag_ty);
19696 break :msg msg;19671 break :msg msg;
...@@ -19706,7 +19681,7 @@ fn zirReify(...@@ -19706,7 +19681,7 @@ fn zirReify(
19706 const gop = union_obj.fields.getOrPutAssumeCapacity(field_name);19681 const gop = union_obj.fields.getOrPutAssumeCapacity(field_name);
19707 if (gop.found_existing) {19682 if (gop.found_existing) {
19708 // TODO: better source location19683 // 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)});
19710 }19685 }
1971119686
19712 const field_ty = type_val.toType();19687 const field_ty = type_val.toType();
...@@ -19762,8 +19737,8 @@ fn zirReify(...@@ -19762,8 +19737,8 @@ fn zirReify(
19762 const enum_ty = union_obj.tag_ty;19737 const enum_ty = union_obj.tag_ty;
19763 for (tag_info.names, 0..) |field_name, field_index| {19738 for (tag_info.names, 0..) |field_name, field_index| {
19764 if (explicit_tags_seen[field_index]) continue;19739 if (explicit_tags_seen[field_index]) continue;
19765 try sema.addFieldErrNote(enum_ty, field_index, msg, "field '{s}' missing, declared here", .{19740 try sema.addFieldErrNote(enum_ty, field_index, msg, "field '{}' missing, declared here", .{
19766 ip.stringToSlice(field_name),19741 field_name.fmt(ip),
19767 });19742 });
19768 }19743 }
19769 try sema.addDeclaredHereNote(msg, union_obj.tag_ty);19744 try sema.addDeclaredHereNote(msg, union_obj.tag_ty);
...@@ -19981,14 +19956,12 @@ fn reifyStruct(...@@ -19981,14 +19956,12 @@ fn reifyStruct(
19981 const field_name = try name_val.toIpString(Type.slice_const_u8, mod);19956 const field_name = try name_val.toIpString(Type.slice_const_u8, mod);
1998219957
19983 if (is_tuple) {19958 if (is_tuple) {
19984 const field_index = std.fmt.parseUnsigned(u32, ip.stringToSlice(field_name), 10) catch {19959 const field_index = field_name.toUnsigned(ip) orelse return sema.fail(
19985 return sema.fail(19960 block,
19986 block,19961 src,
19987 src,19962 "tuple cannot have non-numeric field '{}'",
19988 "tuple cannot have non-numeric field '{s}'",19963 .{field_name.fmt(ip)},
19989 .{ip.stringToSlice(field_name)},19964 );
19990 );
19991 };
1999219965
19993 if (field_index >= fields_len) {19966 if (field_index >= fields_len) {
19994 return sema.fail(19967 return sema.fail(
...@@ -20002,7 +19975,7 @@ fn reifyStruct(...@@ -20002,7 +19975,7 @@ fn reifyStruct(
20002 const gop = struct_obj.fields.getOrPutAssumeCapacity(field_name);19975 const gop = struct_obj.fields.getOrPutAssumeCapacity(field_name);
20003 if (gop.found_existing) {19976 if (gop.found_existing) {
20004 // TODO: better source location19977 // 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)});
20006 }19979 }
2000719980
20008 const field_ty = type_val.toType();19981 const field_ty = type_val.toType();
...@@ -20443,14 +20416,14 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat...@@ -20443,14 +20416,14 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
2044320416
20444 if (maybe_operand_val) |val| {20417 if (maybe_operand_val) |val| {
20445 if (!dest_ty.isAnyError(mod)) {20418 if (!dest_ty.isAnyError(mod)) {
20446 const error_name = mod.intern_pool.stringToSlice(mod.intern_pool.indexToKey(val.toIntern()).err.name);20419 const error_name = mod.intern_pool.indexToKey(val.toIntern()).err.name;
20447 if (!dest_ty.errorSetHasField(error_name, mod)) {20420 if (!Type.errorSetHasFieldIp(ip, dest_ty.toIntern(), error_name)) {
20448 const msg = msg: {20421 const msg = msg: {
20449 const msg = try sema.errMsg(20422 const msg = try sema.errMsg(
20450 block,20423 block,
20451 src,20424 src,
20452 "'error.{s}' not a member of error set '{}'",20425 "'error.{}' not a member of error set '{}'",
20453 .{ error_name, dest_ty.fmt(sema.mod) },20426 .{ error_name.fmt(ip), dest_ty.fmt(sema.mod) },
20454 );20427 );
20455 errdefer msg.destroy(sema.gpa);20428 errdefer msg.destroy(sema.gpa);
20456 try sema.addDeclaredHereNote(msg, dest_ty);20429 try sema.addDeclaredHereNote(msg, dest_ty);
...@@ -21448,7 +21421,7 @@ fn resolveExportOptions(...@@ -21448,7 +21421,7 @@ fn resolveExportOptions(
21448 block: *Block,21421 block: *Block,
21449 src: LazySrcLoc,21422 src: LazySrcLoc,
21450 zir_ref: Zir.Inst.Ref,21423 zir_ref: Zir.Inst.Ref,
21451) CompileError!std.builtin.ExportOptions {21424) CompileError!Module.Export.Options {
21452 const mod = sema.mod;21425 const mod = sema.mod;
21453 const gpa = sema.gpa;21426 const gpa = sema.gpa;
21454 const ip = &mod.intern_pool;21427 const ip = &mod.intern_pool;
...@@ -21492,10 +21465,10 @@ fn resolveExportOptions(...@@ -21492,10 +21465,10 @@ fn resolveExportOptions(
21492 });21465 });
21493 }21466 }
2149421467
21495 return std.builtin.ExportOptions{21468 return .{
21496 .name = name,21469 .name = try ip.getOrPutString(gpa, name),
21497 .linkage = linkage,21470 .linkage = linkage,
21498 .section = section,21471 .section = try ip.getOrPutStringOpt(gpa, section),
21499 .visibility = visibility,21472 .visibility = visibility,
21500 };21473 };
21501}21474}
...@@ -22391,9 +22364,9 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr...@@ -22391,9 +22364,9 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
22391 const msg = try sema.errMsg(22364 const msg = try sema.errMsg(
22392 block,22365 block,
22393 src,22366 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 '{}'",
22395 .{22368 .{
22396 ip.stringToSlice(field_name),22369 field_name.fmt(ip),
22397 field_index,22370 field_index,
22398 field.index,22371 field.index,
22399 parent_ty.fmt(sema.mod),22372 parent_ty.fmt(sema.mod),
...@@ -23440,7 +23413,12 @@ fn resolveExternOptions(...@@ -23440,7 +23413,12 @@ fn resolveExternOptions(
23440 block: *Block,23413 block: *Block,
23441 src: LazySrcLoc,23414 src: LazySrcLoc,
23442 zir_ref: Zir.Inst.Ref,23415 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} {
23444 const mod = sema.mod;23422 const mod = sema.mod;
23445 const gpa = sema.gpa;23423 const gpa = sema.gpa;
23446 const ip = &mod.intern_pool;23424 const ip = &mod.intern_pool;
...@@ -23483,9 +23461,9 @@ fn resolveExternOptions(...@@ -23483,9 +23461,9 @@ fn resolveExternOptions(
23483 return sema.fail(block, linkage_src, "extern symbol must use strong or weak linkage", .{});23461 return sema.fail(block, linkage_src, "extern symbol must use strong or weak linkage", .{});
23484 }23462 }
2348523463
23486 return std.builtin.ExternOptions{23464 return .{
23487 .name = name,23465 .name = try ip.getOrPutString(gpa, name),
23488 .library_name = library_name,23466 .library_name = try ip.getOrPutStringOpt(gpa, library_name),
23489 .linkage = linkage,23467 .linkage = linkage,
23490 .is_thread_local = is_thread_local_val.toBool(),23468 .is_thread_local = is_thread_local_val.toBool(),
23491 };23469 };
...@@ -23533,7 +23511,7 @@ fn zirBuiltinExtern(...@@ -23533,7 +23511,7 @@ fn zirBuiltinExtern(
23533 const new_decl_index = try mod.allocateNewDecl(sema.owner_decl.src_namespace, sema.owner_decl.src_node, null);23511 const new_decl_index = try mod.allocateNewDecl(sema.owner_decl.src_namespace, sema.owner_decl.src_node, null);
23534 errdefer mod.destroyDecl(new_decl_index);23512 errdefer mod.destroyDecl(new_decl_index);
23535 const new_decl = mod.declPtr(new_decl_index);23513 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
23538 {23516 {
23539 const new_var = try mod.intern(.{ .variable = .{23517 const new_var = try mod.intern(.{ .variable = .{
...@@ -24459,8 +24437,8 @@ fn fieldVal(...@@ -24459,8 +24437,8 @@ fn fieldVal(
24459 return sema.fail(24437 return sema.fail(
24460 block,24438 block,
24461 field_name_src,24439 field_name_src,
24462 "no member named '{s}' in '{}'",24440 "no member named '{}' in '{}'",
24463 .{ ip.stringToSlice(field_name), object_ty.fmt(mod) },24441 .{ field_name.fmt(ip), object_ty.fmt(mod) },
24464 );24442 );
24465 }24443 }
24466 },24444 },
...@@ -24483,8 +24461,8 @@ fn fieldVal(...@@ -24483,8 +24461,8 @@ fn fieldVal(
24483 return sema.fail(24461 return sema.fail(
24484 block,24462 block,
24485 field_name_src,24463 field_name_src,
24486 "no member named '{s}' in '{}'",24464 "no member named '{}' in '{}'",
24487 .{ ip.stringToSlice(field_name), object_ty.fmt(mod) },24465 .{ field_name.fmt(ip), object_ty.fmt(mod) },
24488 );24466 );
24489 }24467 }
24490 }24468 }
...@@ -24504,8 +24482,8 @@ fn fieldVal(...@@ -24504,8 +24482,8 @@ fn fieldVal(
24504 .error_set_type => |error_set_type| blk: {24482 .error_set_type => |error_set_type| blk: {
24505 if (error_set_type.nameIndex(ip, field_name) != null) break :blk;24483 if (error_set_type.nameIndex(ip, field_name) != null) break :blk;
24506 const msg = msg: {24484 const msg = msg: {
24507 const msg = try sema.errMsg(block, src, "no error named '{s}' in '{}'", .{24485 const msg = try sema.errMsg(block, src, "no error named '{}' in '{}'", .{
24508 ip.stringToSlice(field_name), child_type.fmt(mod),24486 field_name.fmt(ip), child_type.fmt(mod),
24509 });24487 });
24510 errdefer msg.destroy(sema.gpa);24488 errdefer msg.destroy(sema.gpa);
24511 try sema.addDeclaredHereNote(msg, child_type);24489 try sema.addDeclaredHereNote(msg, child_type);
...@@ -24526,7 +24504,7 @@ fn fieldVal(...@@ -24526,7 +24504,7 @@ fn fieldVal(
24526 const error_set_type = if (!child_type.isAnyError(mod))24504 const error_set_type = if (!child_type.isAnyError(mod))
24527 child_type24505 child_type
24528 else24506 else
24529 try mod.singleErrorSetTypeNts(field_name);24507 try mod.singleErrorSetType(field_name);
24530 return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{24508 return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{
24531 .ty = error_set_type.toIntern(),24509 .ty = error_set_type.toIntern(),
24532 .name = field_name,24510 .name = field_name,
...@@ -24646,8 +24624,8 @@ fn fieldPtr(...@@ -24646,8 +24624,8 @@ fn fieldPtr(
24646 return sema.fail(24624 return sema.fail(
24647 block,24625 block,
24648 field_name_src,24626 field_name_src,
24649 "no member named '{s}' in '{}'",24627 "no member named '{}' in '{}'",
24650 .{ ip.stringToSlice(field_name), object_ty.fmt(mod) },24628 .{ field_name.fmt(ip), object_ty.fmt(mod) },
24651 );24629 );
24652 }24630 }
24653 },24631 },
...@@ -24705,8 +24683,8 @@ fn fieldPtr(...@@ -24705,8 +24683,8 @@ fn fieldPtr(
24705 return sema.fail(24683 return sema.fail(
24706 block,24684 block,
24707 field_name_src,24685 field_name_src,
24708 "no member named '{s}' in '{}'",24686 "no member named '{}' in '{}'",
24709 .{ ip.stringToSlice(field_name), object_ty.fmt(mod) },24687 .{ field_name.fmt(ip), object_ty.fmt(mod) },
24710 );24688 );
24711 }24689 }
24712 },24690 },
...@@ -24728,8 +24706,8 @@ fn fieldPtr(...@@ -24728,8 +24706,8 @@ fn fieldPtr(
24728 if (error_set_type.nameIndex(ip, field_name) != null) {24706 if (error_set_type.nameIndex(ip, field_name) != null) {
24729 break :blk;24707 break :blk;
24730 }24708 }
24731 return sema.fail(block, src, "no error named '{s}' in '{}'", .{24709 return sema.fail(block, src, "no error named '{}' in '{}'", .{
24732 ip.stringToSlice(field_name), child_type.fmt(mod),24710 field_name.fmt(ip), child_type.fmt(mod),
24733 });24711 });
24734 },24712 },
24735 .inferred_error_set_type => {24713 .inferred_error_set_type => {
...@@ -24747,7 +24725,7 @@ fn fieldPtr(...@@ -24747,7 +24725,7 @@ fn fieldPtr(
24747 const error_set_type = if (!child_type.isAnyError(mod))24725 const error_set_type = if (!child_type.isAnyError(mod))
24748 child_type24726 child_type
24749 else24727 else
24750 try mod.singleErrorSetTypeNts(field_name);24728 try mod.singleErrorSetType(field_name);
24751 return sema.analyzeDeclRef(try anon_decl.finish(24729 return sema.analyzeDeclRef(try anon_decl.finish(
24752 error_set_type,24730 error_set_type,
24753 (try mod.intern(.{ .err = .{24731 (try mod.intern(.{ .err = .{
...@@ -24880,10 +24858,10 @@ fn fieldCallBind(...@@ -24880,10 +24858,10 @@ fn fieldCallBind(
24880 if (ip.stringEqlSlice(field_name, "len")) {24858 if (ip.stringEqlSlice(field_name, "len")) {
24881 return .{ .direct = try sema.addIntUnsigned(Type.usize, struct_ty.structFieldCount(mod)) };24859 return .{ .direct = try sema.addIntUnsigned(Type.usize, struct_ty.structFieldCount(mod)) };
24882 }24860 }
24883 if (std.fmt.parseUnsigned(u32, ip.stringToSlice(field_name), 10)) |field_index| {24861 if (field_name.toUnsigned(ip)) |field_index| {
24884 if (field_index >= struct_ty.structFieldCount(mod)) break :find_field;24862 if (field_index >= struct_ty.structFieldCount(mod)) break :find_field;
24885 return sema.finishFieldCallBind(block, src, ptr_ty, struct_ty.structFieldType(field_index, mod), field_index, object_ptr);24863 return sema.finishFieldCallBind(block, src, ptr_ty, struct_ty.structFieldType(field_index, mod), field_index, object_ptr);
24886 } else |_| {}24864 }
24887 } else {24865 } else {
24888 const max = struct_ty.structFieldCount(mod);24866 const max = struct_ty.structFieldCount(mod);
24889 for (0..max) |i_usize| {24867 for (0..max) |i_usize| {
...@@ -24982,12 +24960,15 @@ fn fieldCallBind(...@@ -24982,12 +24960,15 @@ fn fieldCallBind(
24982 };24960 };
2498324961
24984 const msg = msg: {24962 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 });
24986 errdefer msg.destroy(sema.gpa);24967 errdefer msg.destroy(sema.gpa);
24987 try sema.addDeclaredHereNote(msg, concrete_ty);24968 try sema.addDeclaredHereNote(msg, concrete_ty);
24988 if (found_decl) |decl_idx| {24969 if (found_decl) |decl_idx| {
24989 const decl = mod.declPtr(decl_idx);24970 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)});
24991 }24972 }
24992 break :msg msg;24973 break :msg msg;
24993 };24974 };
...@@ -25047,8 +25028,8 @@ fn namespaceLookup(...@@ -25047,8 +25028,8 @@ fn namespaceLookup(
25047 const decl = mod.declPtr(decl_index);25028 const decl = mod.declPtr(decl_index);
25048 if (!decl.is_pub and decl.getFileScope(mod) != block.getFileScope(mod)) {25029 if (!decl.is_pub and decl.getFileScope(mod) != block.getFileScope(mod)) {
25049 const msg = msg: {25030 const msg = msg: {
25050 const msg = try sema.errMsg(block, src, "'{s}' is not marked 'pub'", .{25031 const msg = try sema.errMsg(block, src, "'{}' is not marked 'pub'", .{
25051 mod.intern_pool.stringToSlice(decl_name),25032 decl_name.fmt(&mod.intern_pool),
25052 });25033 });
25053 errdefer msg.destroy(gpa);25034 errdefer msg.destroy(gpa);
25054 try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "declared here", .{});25035 try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "declared here", .{});
...@@ -25299,21 +25280,20 @@ fn tupleFieldIndex(...@@ -25299,21 +25280,20 @@ fn tupleFieldIndex(
25299 sema: *Sema,25280 sema: *Sema,
25300 block: *Block,25281 block: *Block,
25301 tuple_ty: Type,25282 tuple_ty: Type,
25302 field_name_ip: InternPool.NullTerminatedString,25283 field_name: InternPool.NullTerminatedString,
25303 field_name_src: LazySrcLoc,25284 field_name_src: LazySrcLoc,
25304) CompileError!u32 {25285) CompileError!u32 {
25305 const mod = sema.mod;25286 const mod = sema.mod;
25306 const field_name = mod.intern_pool.stringToSlice(field_name_ip);25287 assert(!mod.intern_pool.stringEqlSlice(field_name, "len"));
25307 assert(!std.mem.eql(u8, field_name, "len"));25288 if (field_name.toUnsigned(&mod.intern_pool)) |field_index| {
25308 if (std.fmt.parseUnsigned(u32, field_name, 10)) |field_index| {
25309 if (field_index < tuple_ty.structFieldCount(mod)) return field_index;25289 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 '{}'", .{25290 return sema.fail(block, field_name_src, "index '{}' out of bounds of tuple '{}'", .{
25311 field_name, tuple_ty.fmt(mod),25291 field_name.fmt(&mod.intern_pool), tuple_ty.fmt(mod),
25312 });25292 });
25313 } else |_| {}25293 }
2531425294
25315 return sema.fail(block, field_name_src, "no field named '{s}' in tuple '{}'", .{25295 return sema.fail(block, field_name_src, "no field named '{}' in tuple '{}'", .{
25316 field_name, tuple_ty.fmt(mod),25296 field_name.fmt(&mod.intern_pool), tuple_ty.fmt(mod),
25317 });25297 });
25318}25298}
2531925299
...@@ -25389,8 +25369,8 @@ fn unionFieldPtr(...@@ -25389,8 +25369,8 @@ fn unionFieldPtr(
25389 const msg = try sema.errMsg(block, src, "cannot initialize 'noreturn' field of union", .{});25369 const msg = try sema.errMsg(block, src, "cannot initialize 'noreturn' field of union", .{});
25390 errdefer msg.destroy(sema.gpa);25370 errdefer msg.destroy(sema.gpa);
2539125371
25392 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{s}' declared here", .{25372 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{}' declared here", .{
25393 ip.stringToSlice(field_name),25373 field_name.fmt(ip),
25394 });25374 });
25395 try sema.addDeclaredHereNote(msg, union_ty);25375 try sema.addDeclaredHereNote(msg, union_ty);
25396 break :msg msg;25376 break :msg msg;
...@@ -25413,9 +25393,9 @@ fn unionFieldPtr(...@@ -25413,9 +25393,9 @@ fn unionFieldPtr(
25413 const msg = msg: {25393 const msg = msg: {
25414 const active_index = union_obj.tag_ty.enumTagFieldIndex(un.tag.toValue(), mod).?;25394 const active_index = union_obj.tag_ty.enumTagFieldIndex(un.tag.toValue(), mod).?;
25415 const active_field_name = union_obj.tag_ty.enumFieldName(active_index, mod);25395 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", .{25396 const msg = try sema.errMsg(block, src, "access of union field '{}' while field '{}' is active", .{
25417 ip.stringToSlice(field_name),25397 field_name.fmt(ip),
25418 ip.stringToSlice(active_field_name),25398 active_field_name.fmt(ip),
25419 });25399 });
25420 errdefer msg.destroy(sema.gpa);25400 errdefer msg.destroy(sema.gpa);
25421 try sema.addDeclaredHereNote(msg, union_ty);25401 try sema.addDeclaredHereNote(msg, union_ty);
...@@ -25486,8 +25466,8 @@ fn unionFieldVal(...@@ -25486,8 +25466,8 @@ fn unionFieldVal(
25486 const msg = msg: {25466 const msg = msg: {
25487 const active_index = union_obj.tag_ty.enumTagFieldIndex(un.tag.toValue(), mod).?;25467 const active_index = union_obj.tag_ty.enumTagFieldIndex(un.tag.toValue(), mod).?;
25488 const active_field_name = union_obj.tag_ty.enumFieldName(active_index, mod);25468 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", .{25469 const msg = try sema.errMsg(block, src, "access of union field '{}' while field '{}' is active", .{
25490 ip.stringToSlice(field_name), ip.stringToSlice(active_field_name),25470 field_name.fmt(ip), active_field_name.fmt(ip),
25491 });25471 });
25492 errdefer msg.destroy(sema.gpa);25472 errdefer msg.destroy(sema.gpa);
25493 try sema.addDeclaredHereNote(msg, union_ty);25473 try sema.addDeclaredHereNote(msg, union_ty);
...@@ -26595,8 +26575,8 @@ fn coerceExtra(...@@ -26595,8 +26575,8 @@ fn coerceExtra(
26595 const msg = try sema.errMsg(26575 const msg = try sema.errMsg(
26596 block,26576 block,
26597 inst_src,26577 inst_src,
26598 "no field named '{s}' in enum '{}'",26578 "no field named '{}' in enum '{}'",
26599 .{ mod.intern_pool.stringToSlice(string), dest_ty.fmt(mod) },26579 .{ string.fmt(&mod.intern_pool), dest_ty.fmt(mod) },
26600 );26580 );
26601 errdefer msg.destroy(sema.gpa);26581 errdefer msg.destroy(sema.gpa);
26602 try sema.addDeclaredHereNote(msg, dest_ty);26582 try sema.addDeclaredHereNote(msg, dest_ty);
...@@ -27051,9 +27031,8 @@ const InMemoryCoercionResult = union(enum) {...@@ -27051,9 +27031,8 @@ const InMemoryCoercionResult = union(enum) {
27051 break;27031 break;
27052 },27032 },
27053 .missing_error => |missing_errors| {27033 .missing_error => |missing_errors| {
27054 for (missing_errors) |err_index| {27034 for (missing_errors) |err| {
27055 const err = mod.intern_pool.stringToSlice(err_index);27035 try sema.errNote(block, src, msg, "'error.{}' not a member of destination error set", .{err.fmt(&mod.intern_pool)});
27056 try sema.errNote(block, src, msg, "'error.{s}' not a member of destination error set", .{err});
27057 }27036 }
27058 break;27037 break;
27059 },27038 },
...@@ -28016,7 +27995,12 @@ fn storePtrVal(...@@ -28016,7 +27995,12 @@ fn storePtrVal(
28016 .bad_decl_ty, .bad_ptr_ty => {27995 .bad_decl_ty, .bad_ptr_ty => {
28017 // TODO show the decl declaration site in a note and explain whether the decl27996 // TODO show the decl declaration site in a note and explain whether the decl
28018 // or the pointer is the problematic type27997 // 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 );
28020 },28004 },
28021 }28005 }
28022}28006}
...@@ -28678,7 +28662,12 @@ fn beginComptimePtrLoad(...@@ -28678,7 +28662,12 @@ fn beginComptimePtrLoad(
28678 .null_value => return sema.fail(block, src, "attempt to use null value", .{}),28662 .null_value => return sema.fail(block, src, "attempt to use null value", .{}),
28679 else => switch (mod.intern_pool.indexToKey(tv.val.toIntern())) {28663 else => switch (mod.intern_pool.indexToKey(tv.val.toIntern())) {
28680 .error_union => |error_union| switch (error_union.val) {28664 .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 ),
28682 .payload => |payload| payload,28671 .payload => |payload| payload,
28683 },28672 },
28684 .opt => |opt| switch (opt.val) {28673 .opt => |opt| switch (opt.val) {
...@@ -29077,8 +29066,8 @@ fn coerceEnumToUnion(...@@ -29077,8 +29066,8 @@ fn coerceEnumToUnion(
29077 errdefer msg.destroy(sema.gpa);29066 errdefer msg.destroy(sema.gpa);
2907829067
29079 const field_name = union_obj.fields.keys()[field_index];29068 const field_name = union_obj.fields.keys()[field_index];
29080 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{s}' declared here", .{29069 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{}' declared here", .{
29081 ip.stringToSlice(field_name),29070 field_name.fmt(ip),
29082 });29071 });
29083 try sema.addDeclaredHereNote(msg, union_ty);29072 try sema.addDeclaredHereNote(msg, union_ty);
29084 break :msg msg;29073 break :msg msg;
...@@ -29088,14 +29077,14 @@ fn coerceEnumToUnion(...@@ -29088,14 +29077,14 @@ fn coerceEnumToUnion(
29088 const opv = (try sema.typeHasOnePossibleValue(field_ty)) orelse {29077 const opv = (try sema.typeHasOnePossibleValue(field_ty)) orelse {
29089 const msg = msg: {29078 const msg = msg: {
29090 const field_name = union_obj.fields.keys()[field_index];29079 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 '{}'", .{
29092 inst_ty.fmt(sema.mod), union_ty.fmt(sema.mod),29081 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),
29094 });29083 });
29095 errdefer msg.destroy(sema.gpa);29084 errdefer msg.destroy(sema.gpa);
2909629085
29097 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{s}' declared here", .{29086 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{}' declared here", .{
29098 ip.stringToSlice(field_name),29087 field_name.fmt(ip),
29099 });29088 });
29100 try sema.addDeclaredHereNote(msg, union_ty);29089 try sema.addDeclaredHereNote(msg, union_ty);
29101 break :msg msg;29090 break :msg msg;
...@@ -29165,8 +29154,8 @@ fn coerceEnumToUnion(...@@ -29165,8 +29154,8 @@ fn coerceEnumToUnion(
29165 const field_name = field.key_ptr.*;29154 const field_name = field.key_ptr.*;
29166 const field_ty = field.value_ptr.ty;29155 const field_ty = field.value_ptr.ty;
29167 if (!(try sema.typeHasRuntimeBits(field_ty))) continue;29156 if (!(try sema.typeHasRuntimeBits(field_ty))) continue;
29168 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{s}' has type '{}'", .{29157 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{}' has type '{}'", .{
29169 ip.stringToSlice(field_name),29158 field_name.fmt(ip),
29170 field_ty.fmt(sema.mod),29159 field_ty.fmt(sema.mod),
29171 });29160 });
29172 }29161 }
...@@ -29522,8 +29511,8 @@ fn coerceTupleToStruct(...@@ -29522,8 +29511,8 @@ fn coerceTupleToStruct(
29522 const field = fields.values()[i];29511 const field = fields.values()[i];
29523 const field_src = inst_src; // TODO better source location29512 const field_src = inst_src; // TODO better source location
29524 if (field.default_val == .none) {29513 if (field.default_val == .none) {
29525 const template = "missing struct field: {s}";29514 const template = "missing struct field: {}";
29526 const args = .{ip.stringToSlice(field_name)};29515 const args = .{field_name.fmt(ip)};
29527 if (root_msg) |msg| {29516 if (root_msg) |msg| {
29528 try sema.errNote(block, field_src, msg, template, args);29517 try sema.errNote(block, field_src, msg, template, args);
29529 } else {29518 } else {
...@@ -29666,8 +29655,8 @@ fn coerceTupleToTuple(...@@ -29666,8 +29655,8 @@ fn coerceTupleToTuple(
29666 }29655 }
29667 continue;29656 continue;
29668 }29657 }
29669 const template = "missing struct field: {s}";29658 const template = "missing struct field: {}";
29670 const args = .{ip.stringToSlice(tuple_ty.structFieldName(i, mod))};29659 const args = .{tuple_ty.structFieldName(i, mod).fmt(ip)};
29671 if (root_msg) |msg| {29660 if (root_msg) |msg| {
29672 try sema.errNote(block, field_src, msg, template, args);29661 try sema.errNote(block, field_src, msg, template, args);
29673 } else {29662 } else {
...@@ -30097,7 +30086,7 @@ fn analyzeIsNonErrComptimeOnly(...@@ -30097,7 +30086,7 @@ fn analyzeIsNonErrComptimeOnly(
30097 if (err_union.isUndef(mod)) {30086 if (err_union.isUndef(mod)) {
30098 return sema.addConstUndef(Type.bool);30087 return sema.addConstUndef(Type.bool);
30099 }30088 }
30100 if (err_union.getError(mod) == null) {30089 if (err_union.getErrorName(mod) == .none) {
30101 return Air.Inst.Ref.bool_true;30090 return Air.Inst.Ref.bool_true;
30102 } else {30091 } else {
30103 return Air.Inst.Ref.bool_false;30092 return Air.Inst.Ref.bool_false;
...@@ -32824,15 +32813,16 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void...@@ -32824,15 +32813,16 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void
32824 extra_index += 1;32813 extra_index += 1;
3282532814
32826 // This string needs to outlive the ZIR code.32815 // 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}", .{32816 const field_name = try ip.getOrPutString(gpa, if (field_name_zir) |s|
32828 field_i,32817 s
32829 }));32818 else
32819 try std.fmt.allocPrint(sema.arena, "{d}", .{field_i}));
3283032820
32831 const gop = struct_obj.fields.getOrPutAssumeCapacity(field_name);32821 const gop = struct_obj.fields.getOrPutAssumeCapacity(field_name);
32832 if (gop.found_existing) {32822 if (gop.found_existing) {
32833 const msg = msg: {32823 const msg = msg: {
32834 const field_src = mod.fieldSrcLoc(struct_obj.owner_decl, .{ .index = field_i }).lazy;32824 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)});
32836 errdefer msg.destroy(gpa);32826 errdefer msg.destroy(gpa);
3283732827
32838 const prev_field_index = struct_obj.fields.getIndex(field_name).?;32828 const prev_field_index = struct_obj.fields.getIndex(field_name).?;
...@@ -33297,8 +33287,8 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {...@@ -33297,8 +33287,8 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {
33297 if (gop.found_existing) {33287 if (gop.found_existing) {
33298 const msg = msg: {33288 const msg = msg: {
33299 const field_src = mod.fieldSrcLoc(union_obj.owner_decl, .{ .index = field_i }).lazy;33289 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}'", .{33290 const msg = try sema.errMsg(&block_scope, field_src, "duplicate union field: '{}'", .{
33301 ip.stringToSlice(field_name),33291 field_name.fmt(ip),
33302 });33292 });
33303 errdefer msg.destroy(gpa);33293 errdefer msg.destroy(gpa);
3330433294
...@@ -33319,8 +33309,8 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {...@@ -33319,8 +33309,8 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {
33319 .index = field_i,33309 .index = field_i,
33320 .range = .type,33310 .range = .type,
33321 }).lazy;33311 }).lazy;
33322 const msg = try sema.errMsg(&block_scope, ty_src, "no field named '{s}' in enum '{}'", .{33312 const msg = try sema.errMsg(&block_scope, ty_src, "no field named '{}' in enum '{}'", .{
33323 ip.stringToSlice(field_name), union_obj.tag_ty.fmt(mod),33313 field_name.fmt(ip), union_obj.tag_ty.fmt(mod),
33324 });33314 });
33325 errdefer msg.destroy(sema.gpa);33315 errdefer msg.destroy(sema.gpa);
33326 try sema.addDeclaredHereNote(msg, union_obj.tag_ty);33316 try sema.addDeclaredHereNote(msg, union_obj.tag_ty);
...@@ -33412,8 +33402,8 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {...@@ -33412,8 +33402,8 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {
33412 const enum_ty = union_obj.tag_ty;33402 const enum_ty = union_obj.tag_ty;
33413 for (tag_info.names, 0..) |field_name, field_index| {33403 for (tag_info.names, 0..) |field_name, field_index| {
33414 if (explicit_tags_seen[field_index]) continue;33404 if (explicit_tags_seen[field_index]) continue;
33415 try sema.addFieldErrNote(enum_ty, field_index, msg, "field '{s}' missing, declared here", .{33405 try sema.addFieldErrNote(enum_ty, field_index, msg, "field '{}' missing, declared here", .{
33416 ip.stringToSlice(field_name),33406 field_name.fmt(ip),
33417 });33407 });
33418 }33408 }
33419 try sema.addDeclaredHereNote(msg, union_obj.tag_ty);33409 try sema.addDeclaredHereNote(msg, union_obj.tag_ty);
...@@ -33442,22 +33432,12 @@ fn generateUnionTagTypeNumbered(...@@ -33442,22 +33432,12 @@ fn generateUnionTagTypeNumbered(
33442) !Type {33432) !Type {
33443 const mod = sema.mod;33433 const mod = sema.mod;
33444 const gpa = sema.gpa;33434 const gpa = sema.gpa;
33445 const ip = &mod.intern_pool;
3344633435
33447 const src_decl = mod.declPtr(block.src_decl);33436 const src_decl = mod.declPtr(block.src_decl);
33448 const new_decl_index = try mod.allocateNewDecl(block.namespace, src_decl.src_node, block.wip_capture_scope);33437 const new_decl_index = try mod.allocateNewDecl(block.namespace, src_decl.src_node, block.wip_capture_scope);
33449 errdefer mod.destroyDecl(new_decl_index);33438 errdefer mod.destroyDecl(new_decl_index);
33450 const name = name: {33439 const fqn = try union_obj.getFullyQualifiedName(mod);
33451 const prefix = "@typeInfo(";33440 const name = try mod.intern_pool.getOrPutStringFmt(gpa, "@typeInfo({}).Union.tag_type.?", .{fqn.fmt(&mod.intern_pool)});
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 };
33461 try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, block.namespace, .{33441 try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, block.namespace, .{
33462 .ty = Type.noreturn,33442 .ty = Type.noreturn,
33463 .val = Value.@"unreachable",33443 .val = Value.@"unreachable",
...@@ -33496,7 +33476,6 @@ fn generateUnionTagTypeSimple(...@@ -33496,7 +33476,6 @@ fn generateUnionTagTypeSimple(
33496) !Type {33476) !Type {
33497 const mod = sema.mod;33477 const mod = sema.mod;
33498 const gpa = sema.gpa;33478 const gpa = sema.gpa;
33499 const ip = &mod.intern_pool;
3350033479
33501 const new_decl_index = new_decl_index: {33480 const new_decl_index = new_decl_index: {
33502 const union_obj = maybe_union_obj orelse {33481 const union_obj = maybe_union_obj orelse {
...@@ -33508,17 +33487,8 @@ fn generateUnionTagTypeSimple(...@@ -33508,17 +33487,8 @@ fn generateUnionTagTypeSimple(
33508 const src_decl = mod.declPtr(block.src_decl);33487 const src_decl = mod.declPtr(block.src_decl);
33509 const new_decl_index = try mod.allocateNewDecl(block.namespace, src_decl.src_node, block.wip_capture_scope);33488 const new_decl_index = try mod.allocateNewDecl(block.namespace, src_decl.src_node, block.wip_capture_scope);
33510 errdefer mod.destroyDecl(new_decl_index);33489 errdefer mod.destroyDecl(new_decl_index);
33511 const name = name: {33490 const fqn = try union_obj.getFullyQualifiedName(mod);
33512 const prefix = "@typeInfo(";33491 const name = try mod.intern_pool.getOrPutStringFmt(gpa, "@typeInfo({}).Union.tag_type.?", .{fqn.fmt(&mod.intern_pool)});
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 };
33522 try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, block.namespace, .{33492 try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, block.namespace, .{
33523 .ty = Type.noreturn,33493 .ty = Type.noreturn,
33524 .val = Value.@"unreachable",33494 .val = Value.@"unreachable",
...@@ -34456,8 +34426,8 @@ fn anonStructFieldIndex(...@@ -34456,8 +34426,8 @@ fn anonStructFieldIndex(
34456 },34426 },
34457 else => unreachable,34427 else => unreachable,
34458 }34428 }
34459 return sema.fail(block, field_src, "no field named '{s}' in anonymous struct '{}'", .{34429 return sema.fail(block, field_src, "no field named '{}' in anonymous struct '{}'", .{
34460 mod.intern_pool.stringToSlice(field_name), struct_ty.fmt(sema.mod),34430 field_name.fmt(&mod.intern_pool), struct_ty.fmt(sema.mod),
34461 });34431 });
34462}34432}
3446334433
src/TypedValue.zig+31-35
...@@ -76,6 +76,7 @@ pub fn print(...@@ -76,6 +76,7 @@ pub fn print(
76) (@TypeOf(writer).Error || Allocator.Error)!void {76) (@TypeOf(writer).Error || Allocator.Error)!void {
77 var val = tv.val;77 var val = tv.val;
78 var ty = tv.ty;78 var ty = tv.ty;
79 const ip = &mod.intern_pool;
79 while (true) switch (val.ip_index) {80 while (true) switch (val.ip_index) {
80 .none => switch (val.tag()) {81 .none => switch (val.tag()) {
81 .aggregate => return printAggregate(ty, val, writer, level, mod),82 .aggregate => return printAggregate(ty, val, writer, level, mod),
...@@ -87,7 +88,7 @@ pub fn print(...@@ -87,7 +88,7 @@ pub fn print(
87 try writer.writeAll(".{ ");88 try writer.writeAll(".{ ");
8889
89 try print(.{90 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,
91 .val = union_val.tag,92 .val = union_val.tag,
92 }, writer, level - 1, mod);93 }, writer, level - 1, mod);
93 try writer.writeAll(" = ");94 try writer.writeAll(" = ");
...@@ -174,7 +175,7 @@ pub fn print(...@@ -174,7 +175,7 @@ pub fn print(
174 ty = ty.optionalChild(mod);175 ty = ty.optionalChild(mod);
175 },176 },
176 },177 },
177 else => switch (mod.intern_pool.indexToKey(val.toIntern())) {178 else => switch (ip.indexToKey(val.toIntern())) {
178 .int_type,179 .int_type,
179 .ptr_type,180 .ptr_type,
180 .array_type,181 .array_type,
...@@ -200,11 +201,11 @@ pub fn print(...@@ -200,11 +201,11 @@ pub fn print(
200 else => return writer.writeAll(@tagName(simple_value)),201 else => return writer.writeAll(@tagName(simple_value)),
201 },202 },
202 .variable => return writer.writeAll("(variable)"),203 .variable => return writer.writeAll("(variable)"),
203 .extern_func => |extern_func| return writer.print("(extern function '{s}')", .{204 .extern_func => |extern_func| return writer.print("(extern function '{}')", .{
204 mod.intern_pool.stringToSlice(mod.declPtr(extern_func.decl).name),205 mod.declPtr(extern_func.decl).name.fmt(ip),
205 }),206 }),
206 .func => |func| return writer.print("(function '{s}')", .{207 .func => |func| return writer.print("(function '{}')", .{
207 mod.intern_pool.stringToSlice(mod.declPtr(mod.funcPtr(func.index).owner_decl).name),208 mod.declPtr(mod.funcPtr(func.index).owner_decl).name.fmt(ip),
208 }),209 }),
209 .int => |int| switch (int.storage) {210 .int => |int| switch (int.storage) {
210 inline .u64, .i64, .big_int => |x| return writer.print("{}", .{x}),211 inline .u64, .i64, .big_int => |x| return writer.print("{}", .{x}),
...@@ -215,29 +216,28 @@ pub fn print(...@@ -215,29 +216,28 @@ pub fn print(
215 lazy_ty.toType().abiSize(mod),216 lazy_ty.toType().abiSize(mod),
216 }),217 }),
217 },218 },
218 .err => |err| return writer.print("error.{s}", .{219 .err => |err| return writer.print("error.{}", .{
219 mod.intern_pool.stringToSlice(err.name),220 err.name.fmt(ip),
220 }),221 }),
221 .error_union => |error_union| switch (error_union.val) {222 .error_union => |error_union| switch (error_union.val) {
222 .err_name => |err_name| return writer.print("error.{s}", .{223 .err_name => |err_name| return writer.print("error.{}", .{
223 mod.intern_pool.stringToSlice(err_name),224 err_name.fmt(ip),
224 }),225 }),
225 .payload => |payload| {226 .payload => |payload| {
226 val = payload.toValue();227 val = payload.toValue();
227 ty = ty.errorUnionPayload(mod);228 ty = ty.errorUnionPayload(mod);
228 },229 },
229 },230 },
230 .enum_literal => |enum_literal| return writer.print(".{s}", .{231 .enum_literal => |enum_literal| return writer.print(".{}", .{
231 mod.intern_pool.stringToSlice(enum_literal),232 enum_literal.fmt(ip),
232 }),233 }),
233 .enum_tag => |enum_tag| {234 .enum_tag => |enum_tag| {
234 if (level == 0) {235 if (level == 0) {
235 return writer.writeAll("(enum)");236 return writer.writeAll("(enum)");
236 }237 }
237 const enum_type = mod.intern_pool.indexToKey(ty.toIntern()).enum_type;238 const enum_type = ip.indexToKey(ty.toIntern()).enum_type;
238 if (enum_type.tagValueIndex(&mod.intern_pool, val.toIntern())) |tag_index| {239 if (enum_type.tagValueIndex(ip, val.toIntern())) |tag_index| {
239 const tag_name = mod.intern_pool.stringToSlice(enum_type.names[tag_index]);240 try writer.print(".{i}", .{enum_type.names[tag_index].fmt(ip)});
240 try writer.print(".{}", .{std.zig.fmtId(tag_name)});
241 return;241 return;
242 }242 }
243 try writer.writeAll("@intToEnum(");243 try writer.writeAll("@intToEnum(");
...@@ -247,7 +247,7 @@ pub fn print(...@@ -247,7 +247,7 @@ pub fn print(
247 }, writer, level - 1, mod);247 }, writer, level - 1, mod);
248 try writer.writeAll(", ");248 try writer.writeAll(", ");
249 try print(.{249 try print(.{
250 .ty = mod.intern_pool.typeOf(enum_tag.int).toType(),250 .ty = ip.typeOf(enum_tag.int).toType(),
251 .val = enum_tag.int.toValue(),251 .val = enum_tag.int.toValue(),
252 }, writer, level - 1, mod);252 }, writer, level - 1, mod);
253 try writer.writeAll(")");253 try writer.writeAll(")");
...@@ -259,13 +259,13 @@ pub fn print(...@@ -259,13 +259,13 @@ pub fn print(
259 },259 },
260 .ptr => |ptr| {260 .ptr => |ptr| {
261 if (ptr.addr == .int) {261 if (ptr.addr == .int) {
262 const i = mod.intern_pool.indexToKey(ptr.addr.int).int;262 const i = ip.indexToKey(ptr.addr.int).int;
263 switch (i.storage) {263 switch (i.storage) {
264 inline else => |addr| return writer.print("{x:0>8}", .{addr}),264 inline else => |addr| return writer.print("{x:0>8}", .{addr}),
265 }265 }
266 }266 }
267267
268 const ptr_ty = mod.intern_pool.indexToKey(ty.toIntern()).ptr_type;268 const ptr_ty = ip.indexToKey(ty.toIntern()).ptr_type;
269 if (ptr_ty.flags.size == .Slice) {269 if (ptr_ty.flags.size == .Slice) {
270 if (level == 0) {270 if (level == 0) {
271 return writer.writeAll(".{ ... }");271 return writer.writeAll(".{ ... }");
...@@ -301,7 +301,7 @@ pub fn print(...@@ -301,7 +301,7 @@ pub fn print(
301 switch (ptr.addr) {301 switch (ptr.addr) {
302 .decl => |decl_index| {302 .decl => |decl_index| {
303 const decl = mod.declPtr(decl_index);303 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)});
305 return print(.{305 return print(.{
306 .ty = decl.ty,306 .ty = decl.ty,
307 .val = decl.val,307 .val = decl.val,
...@@ -309,7 +309,7 @@ pub fn print(...@@ -309,7 +309,7 @@ pub fn print(
309 },309 },
310 .mut_decl => |mut_decl| {310 .mut_decl => |mut_decl| {
311 const decl = mod.declPtr(mut_decl.decl);311 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)});
313 return print(.{313 return print(.{
314 .ty = decl.ty,314 .ty = decl.ty,
315 .val = decl.val,315 .val = decl.val,
...@@ -317,7 +317,7 @@ pub fn print(...@@ -317,7 +317,7 @@ pub fn print(
317 },317 },
318 .comptime_field => |field_val_ip| {318 .comptime_field => |field_val_ip| {
319 return print(.{319 return print(.{
320 .ty = mod.intern_pool.typeOf(field_val_ip).toType(),320 .ty = ip.typeOf(field_val_ip).toType(),
321 .val = field_val_ip.toValue(),321 .val = field_val_ip.toValue(),
322 }, writer, level - 1, mod);322 }, writer, level - 1, mod);
323 },323 },
...@@ -325,27 +325,27 @@ pub fn print(...@@ -325,27 +325,27 @@ pub fn print(
325 .eu_payload => |eu_ip| {325 .eu_payload => |eu_ip| {
326 try writer.writeAll("(payload of ");326 try writer.writeAll("(payload of ");
327 try print(.{327 try print(.{
328 .ty = mod.intern_pool.typeOf(eu_ip).toType(),328 .ty = ip.typeOf(eu_ip).toType(),
329 .val = eu_ip.toValue(),329 .val = eu_ip.toValue(),
330 }, writer, level - 1, mod);330 }, writer, level - 1, mod);
331 try writer.writeAll(")");331 try writer.writeAll(")");
332 },332 },
333 .opt_payload => |opt_ip| {333 .opt_payload => |opt_ip| {
334 try print(.{334 try print(.{
335 .ty = mod.intern_pool.typeOf(opt_ip).toType(),335 .ty = ip.typeOf(opt_ip).toType(),
336 .val = opt_ip.toValue(),336 .val = opt_ip.toValue(),
337 }, writer, level - 1, mod);337 }, writer, level - 1, mod);
338 try writer.writeAll(".?");338 try writer.writeAll(".?");
339 },339 },
340 .elem => |elem| {340 .elem => |elem| {
341 try print(.{341 try print(.{
342 .ty = mod.intern_pool.typeOf(elem.base).toType(),342 .ty = ip.typeOf(elem.base).toType(),
343 .val = elem.base.toValue(),343 .val = elem.base.toValue(),
344 }, writer, level - 1, mod);344 }, writer, level - 1, mod);
345 try writer.print("[{}]", .{elem.index});345 try writer.print("[{}]", .{elem.index});
346 },346 },
347 .field => |field| {347 .field => |field| {
348 const container_ty = mod.intern_pool.typeOf(field.base).toType();348 const container_ty = ip.typeOf(field.base).toType();
349 try print(.{349 try print(.{
350 .ty = container_ty,350 .ty = container_ty,
351 .val = field.base.toValue(),351 .val = field.base.toValue(),
...@@ -356,14 +356,12 @@ pub fn print(...@@ -356,14 +356,12 @@ pub fn print(
356 if (container_ty.isTuple(mod)) {356 if (container_ty.isTuple(mod)) {
357 try writer.print("[{d}]", .{field.index});357 try writer.print("[{d}]", .{field.index});
358 }358 }
359 const field_name_ip = container_ty.structFieldName(@intCast(usize, field.index), mod);359 const field_name = container_ty.structFieldName(@intCast(usize, field.index), mod);
360 const field_name = mod.intern_pool.stringToSlice(field_name_ip);360 try writer.print(".{i}", .{field_name.fmt(ip)});
361 try writer.print(".{}", .{std.zig.fmtId(field_name)});
362 },361 },
363 .Union => {362 .Union => {
364 const field_name_ip = container_ty.unionFields(mod).keys()[@intCast(usize, field.index)];363 const field_name = container_ty.unionFields(mod).keys()[@intCast(usize, field.index)];
365 const field_name = mod.intern_pool.stringToSlice(field_name_ip);364 try writer.print(".{i}", .{field_name.fmt(ip)});
366 try writer.print(".{}", .{std.zig.fmtId(field_name)});
367 },365 },
368 .Pointer => {366 .Pointer => {
369 std.debug.assert(container_ty.isSlice(mod));367 std.debug.assert(container_ty.isSlice(mod));
...@@ -440,9 +438,7 @@ fn printAggregate(...@@ -440,9 +438,7 @@ fn printAggregate(
440 else => unreachable,438 else => unreachable,
441 };439 };
442440
443 if (field_name.unwrap()) |name_ip| try writer.print(".{s} = ", .{441 if (field_name.unwrap()) |name| try writer.print(".{} = ", .{name.fmt(&mod.intern_pool)});
444 mod.intern_pool.stringToSlice(name_ip),
445 });
446 try print(.{442 try print(.{
447 .ty = ty.structFieldType(i, mod),443 .ty = ty.structFieldType(i, mod),
448 .val = try val.fieldValue(mod, i),444 .val = try val.fieldValue(mod, i),
src/codegen/c.zig+4-4
...@@ -1850,9 +1850,9 @@ pub const DeclGen = struct {...@@ -1850,9 +1850,9 @@ pub const DeclGen = struct {
1850 try mod.markDeclAlive(decl);1850 try mod.markDeclAlive(decl);
18511851
1852 if (mod.decl_exports.get(decl_index)) |exports| {1852 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)});
1854 } else if (decl.isExtern(mod)) {1854 } 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)});
1856 } else {1856 } else {
1857 // MSVC has a limit of 4095 character token length limit, and fmtIdent can (worst case),1857 // MSVC has a limit of 4095 character token length limit, and fmtIdent can (worst case),
1858 // expand to 3x the length of its input, but let's cut it off at a much shorter limit.1858 // 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 {...@@ -2481,8 +2481,8 @@ fn genExports(o: *Object) !void {
2481 try fwd_decl_writer.writeAll("zig_export(");2481 try fwd_decl_writer.writeAll("zig_export(");
2482 try o.dg.renderFunctionSignature(fwd_decl_writer, o.dg.decl_index.unwrap().?, .forward, .{ .export_index = @intCast(u32, i) });2482 try o.dg.renderFunctionSignature(fwd_decl_writer, o.dg.decl_index.unwrap().?, .forward, .{ .export_index = @intCast(u32, i) });
2483 try fwd_decl_writer.print(", {s}, {s});\n", .{2483 try fwd_decl_writer.print(", {s}, {s});\n", .{
2484 fmtStringLiteral(ip.stringToSlice(exports.items[0].name), null),2484 fmtStringLiteral(ip.stringToSlice(exports.items[0].opts.name), null),
2485 fmtStringLiteral(ip.stringToSlice(@"export".name), null),2485 fmtStringLiteral(ip.stringToSlice(@"export".opts.name), null),
2486 });2486 });
2487 }2487 }
2488 }2488 }
src/codegen/llvm.zig+18-19
...@@ -687,11 +687,9 @@ pub const Object = struct {...@@ -687,11 +687,9 @@ pub const Object = struct {
687 for (export_list.items) |exp| {687 for (export_list.items) |exp| {
688 // Detect if the LLVM global has already been created as an extern. In such688 // Detect if the LLVM global has already been created as an extern. In such
689 // case, we need to replace all uses of it with this exported global.689 // case, we need to replace all uses of it with this exported global.
690 // TODO update std.builtin.ExportOptions to have the name be a690 const exp_name = mod.intern_pool.stringToSlice(exp.opts.name);
691 // null-terminated slice.
692 const exp_name_z = mod.intern_pool.stringToSlice(exp.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;
695 if (other_global == llvm_global) continue;693 if (other_global == llvm_global) continue;
696694
697 other_global.replaceAllUsesWith(llvm_global);695 other_global.replaceAllUsesWith(llvm_global);
...@@ -1320,7 +1318,7 @@ pub const Object = struct {...@@ -1320,7 +1318,7 @@ pub const Object = struct {
1320 }1318 }
1321 }1319 }
1322 } else if (exports.len != 0) {1320 } 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);
1324 llvm_global.setValueName2(exp_name.ptr, exp_name.len);1322 llvm_global.setValueName2(exp_name.ptr, exp_name.len);
1325 llvm_global.setUnnamedAddr(.False);1323 llvm_global.setUnnamedAddr(.False);
1326 if (mod.wantDllExports()) llvm_global.setDLLStorageClass(.DLLExport);1324 if (mod.wantDllExports()) llvm_global.setDLLStorageClass(.DLLExport);
...@@ -1335,18 +1333,18 @@ pub const Object = struct {...@@ -1335,18 +1333,18 @@ pub const Object = struct {
1335 di_global.replaceLinkageName(linkage_name);1333 di_global.replaceLinkageName(linkage_name);
1336 }1334 }
1337 }1335 }
1338 switch (exports[0].linkage) {1336 switch (exports[0].opts.linkage) {
1339 .Internal => unreachable,1337 .Internal => unreachable,
1340 .Strong => llvm_global.setLinkage(.External),1338 .Strong => llvm_global.setLinkage(.External),
1341 .Weak => llvm_global.setLinkage(.WeakODR),1339 .Weak => llvm_global.setLinkage(.WeakODR),
1342 .LinkOnce => llvm_global.setLinkage(.LinkOnceODR),1340 .LinkOnce => llvm_global.setLinkage(.LinkOnceODR),
1343 }1341 }
1344 switch (exports[0].visibility) {1342 switch (exports[0].opts.visibility) {
1345 .default => llvm_global.setVisibility(.Default),1343 .default => llvm_global.setVisibility(.Default),
1346 .hidden => llvm_global.setVisibility(.Hidden),1344 .hidden => llvm_global.setVisibility(.Hidden),
1347 .protected => llvm_global.setVisibility(.Protected),1345 .protected => llvm_global.setVisibility(.Protected),
1348 }1346 }
1349 if (mod.intern_pool.stringToSliceUnwrap(exports[0].section)) |section| {1347 if (mod.intern_pool.stringToSliceUnwrap(exports[0].opts.section)) |section| {
1350 llvm_global.setSection(section);1348 llvm_global.setSection(section);
1351 }1349 }
1352 if (decl.val.getVariable(mod)) |variable| {1350 if (decl.val.getVariable(mod)) |variable| {
...@@ -1362,7 +1360,7 @@ pub const Object = struct {...@@ -1362,7 +1360,7 @@ pub const Object = struct {
1362 // Until then we iterate over existing aliases and make them point1360 // Until then we iterate over existing aliases and make them point
1363 // to the correct decl, or otherwise add a new alias. Old aliases are leaked.1361 // to the correct decl, or otherwise add a new alias. Old aliases are leaked.
1364 for (exports[1..]) |exp| {1362 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
1367 if (self.llvm_module.getNamedGlobalAlias(exp_name_z.ptr, exp_name_z.len)) |alias| {1365 if (self.llvm_module.getNamedGlobalAlias(exp_name_z.ptr, exp_name_z.len)) |alias| {
1368 alias.setAliasee(llvm_global);1366 alias.setAliasee(llvm_global);
...@@ -2539,10 +2537,10 @@ pub const DeclGen = struct {...@@ -2539,10 +2537,10 @@ pub const DeclGen = struct {
25392537
2540 const fn_type = try dg.lowerType(zig_fn_type);2538 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
2544 const llvm_addrspace = toLlvmAddressSpace(decl.@"addrspace", target);2542 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);
2546 gop.value_ptr.* = llvm_fn;2544 gop.value_ptr.* = llvm_fn;
25472545
2548 const is_extern = decl.isExtern(mod);2546 const is_extern = decl.isExtern(mod);
...@@ -2693,7 +2691,7 @@ pub const DeclGen = struct {...@@ -2693,7 +2691,7 @@ pub const DeclGen = struct {
26932691
2694 const mod = dg.module;2692 const mod = dg.module;
2695 const decl = mod.declPtr(decl_index);2693 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
2698 const target = mod.getTarget();2696 const target = mod.getTarget();
26992697
...@@ -2702,7 +2700,7 @@ pub const DeclGen = struct {...@@ -2702,7 +2700,7 @@ pub const DeclGen = struct {
27022700
2703 const llvm_global = dg.object.llvm_module.addGlobalInAddressSpace(2701 const llvm_global = dg.object.llvm_module.addGlobalInAddressSpace(
2704 llvm_type,2702 llvm_type,
2705 fqn,2703 mod.intern_pool.stringToSlice(fqn),
2706 llvm_actual_addrspace,2704 llvm_actual_addrspace,
2707 );2705 );
2708 gop.value_ptr.* = llvm_global;2706 gop.value_ptr.* = llvm_global;
...@@ -5942,6 +5940,8 @@ pub const FuncGen = struct {...@@ -5942,6 +5940,8 @@ pub const FuncGen = struct {
5942 .base_line = self.base_line,5940 .base_line = self.base_line,
5943 });5941 });
59445942
5943 const fqn = try decl.getFullyQualifiedName(mod);
5944
5945 const is_internal_linkage = !mod.decl_exports.contains(decl_index);5945 const is_internal_linkage = !mod.decl_exports.contains(decl_index);
5946 const fn_ty = try mod.funcType(.{5946 const fn_ty = try mod.funcType(.{
5947 .param_types = &.{},5947 .param_types = &.{},
...@@ -5959,11 +5959,10 @@ pub const FuncGen = struct {...@@ -5959,11 +5959,10 @@ pub const FuncGen = struct {
5959 .addrspace_is_generic = false,5959 .addrspace_is_generic = false,
5960 });5960 });
5961 const fn_di_ty = try self.dg.object.lowerDebugType(fn_ty, .full);5961 const fn_di_ty = try self.dg.object.lowerDebugType(fn_ty, .full);
5962 const fqn = mod.intern_pool.stringToSlice(try decl.getFullyQualifiedName(mod));
5963 const subprogram = dib.createFunction(5962 const subprogram = dib.createFunction(
5964 di_file.toScope(),5963 di_file.toScope(),
5965 mod.intern_pool.stringToSlice(decl.name),5964 mod.intern_pool.stringToSlice(decl.name),
5966 fqn,5965 mod.intern_pool.stringToSlice(fqn),
5967 di_file,5966 di_file,
5968 line_number,5967 line_number,
5969 fn_di_ty,5968 fn_di_ty,
...@@ -8661,8 +8660,8 @@ pub const FuncGen = struct {...@@ -8661,8 +8660,8 @@ pub const FuncGen = struct {
8661 defer arena_allocator.deinit();8660 defer arena_allocator.deinit();
8662 const arena = arena_allocator.allocator();8661 const arena = arena_allocator.allocator();
86638662
8664 const fqn = mod.intern_pool.stringToSlice(try mod.declPtr(enum_type.decl).getFullyQualifiedName(mod));8663 const fqn = 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});8664 const llvm_fn_name = try std.fmt.allocPrintZ(arena, "__zig_is_named_enum_value_{}", .{fqn.fmt(&mod.intern_pool)});
86668665
8667 const param_types = [_]*llvm.Type{try self.dg.lowerType(enum_type.tag_ty.toType())};8666 const param_types = [_]*llvm.Type{try self.dg.lowerType(enum_type.tag_ty.toType())};
86688667
...@@ -8733,8 +8732,8 @@ pub const FuncGen = struct {...@@ -8733,8 +8732,8 @@ pub const FuncGen = struct {
8733 defer arena_allocator.deinit();8732 defer arena_allocator.deinit();
8734 const arena = arena_allocator.allocator();8733 const arena = arena_allocator.allocator();
87358734
8736 const fqn = mod.intern_pool.stringToSlice(try mod.declPtr(enum_type.decl).getFullyQualifiedName(mod));8735 const fqn = try mod.declPtr(enum_type.decl).getFullyQualifiedName(mod);
8737 const llvm_fn_name = try std.fmt.allocPrintZ(arena, "__zig_tag_name_{s}", .{fqn});8736 const llvm_fn_name = try std.fmt.allocPrintZ(arena, "__zig_tag_name_{}", .{fqn.fmt(&mod.intern_pool)});
87388737
8739 const slice_ty = Type.slice_const_u8_sentinel_0;8738 const slice_ty = Type.slice_const_u8_sentinel_0;
8740 const llvm_ret_ty = try self.dg.lowerType(slice_ty);8739 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...@@ -294,7 +294,7 @@ pub fn flushModule(self: *C, _: *Compilation, prog_node: *std.Progress.Node) !vo
294 defer export_names.deinit(gpa);294 defer export_names.deinit(gpa);
295 try export_names.ensureTotalCapacity(gpa, @intCast(u32, module.decl_exports.entries.len));295 try export_names.ensureTotalCapacity(gpa, @intCast(u32, module.decl_exports.entries.len));
296 for (module.decl_exports.values()) |exports| for (exports.items) |@"export"|296 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
299 while (f.remaining_decls.popOrNull()) |kv| {299 while (f.remaining_decls.popOrNull()) |kv| {
300 const decl_index = kv.key;300 const decl_index = kv.key;
src/link/Coff.zig+12-13
...@@ -1430,20 +1430,20 @@ pub fn updateDeclExports(...@@ -1430,20 +1430,20 @@ pub fn updateDeclExports(
1430 else => std.builtin.CallingConvention.C,1430 else => std.builtin.CallingConvention.C,
1431 };1431 };
1432 const decl_cc = exported_decl.ty.fnCallingConvention(mod);1432 const decl_cc = exported_decl.ty.fnCallingConvention(mod);
1433 if (decl_cc == .C and ip.stringEqlSlice(exp.name, "main") and1433 if (decl_cc == .C and ip.stringEqlSlice(exp.opts.name, "main") and
1434 self.base.options.link_libc)1434 self.base.options.link_libc)
1435 {1435 {
1436 mod.stage1_flags.have_c_main = true;1436 mod.stage1_flags.have_c_main = true;
1437 } else if (decl_cc == winapi_cc and self.base.options.target.os.tag == .windows) {1437 } 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")) {
1439 mod.stage1_flags.have_winmain = true;1439 mod.stage1_flags.have_winmain = true;
1440 } else if (ip.stringEqlSlice(exp.name, "wWinMain")) {1440 } else if (ip.stringEqlSlice(exp.opts.name, "wWinMain")) {
1441 mod.stage1_flags.have_wwinmain = true;1441 mod.stage1_flags.have_wwinmain = true;
1442 } else if (ip.stringEqlSlice(exp.name, "WinMainCRTStartup")) {1442 } else if (ip.stringEqlSlice(exp.opts.name, "WinMainCRTStartup")) {
1443 mod.stage1_flags.have_winmain_crt_startup = true;1443 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")) {
1445 mod.stage1_flags.have_wwinmain_crt_startup = true;1445 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")) {
1447 mod.stage1_flags.have_dllmain_crt_startup = true;1447 mod.stage1_flags.have_dllmain_crt_startup = true;
1448 }1448 }
1449 }1449 }
...@@ -1461,10 +1461,9 @@ pub fn updateDeclExports(...@@ -1461,10 +1461,9 @@ pub fn updateDeclExports(
1461 const decl_metadata = self.decls.getPtr(decl_index).?;1461 const decl_metadata = self.decls.getPtr(decl_index).?;
14621462
1463 for (exports) |exp| {1463 for (exports) |exp| {
1464 const exp_name = mod.intern_pool.stringToSlice(exp.name);1464 log.debug("adding new export '{}'", .{exp.opts.name.fmt(&mod.intern_pool)});
1465 log.debug("adding new export '{s}'", .{exp_name});
14661465
1467 if (mod.intern_pool.stringToSliceUnwrap(exp.section)) |section_name| {1466 if (mod.intern_pool.stringToSliceUnwrap(exp.opts.section)) |section_name| {
1468 if (!mem.eql(u8, section_name, ".text")) {1467 if (!mem.eql(u8, section_name, ".text")) {
1469 try mod.failed_exports.putNoClobber(1468 try mod.failed_exports.putNoClobber(
1470 gpa,1469 gpa,
...@@ -1480,7 +1479,7 @@ pub fn updateDeclExports(...@@ -1480,7 +1479,7 @@ pub fn updateDeclExports(
1480 }1479 }
1481 }1480 }
14821481
1483 if (exp.linkage == .LinkOnce) {1482 if (exp.opts.linkage == .LinkOnce) {
1484 try mod.failed_exports.putNoClobber(1483 try mod.failed_exports.putNoClobber(
1485 gpa,1484 gpa,
1486 exp,1485 exp,
...@@ -1494,19 +1493,19 @@ pub fn updateDeclExports(...@@ -1494,19 +1493,19 @@ pub fn updateDeclExports(
1494 continue;1493 continue;
1495 }1494 }
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: {
1498 const sym_index = try self.allocateSymbol();1497 const sym_index = try self.allocateSymbol();
1499 try decl_metadata.exports.append(gpa, sym_index);1498 try decl_metadata.exports.append(gpa, sym_index);
1500 break :blk sym_index;1499 break :blk sym_index;
1501 };1500 };
1502 const sym_loc = SymbolWithLoc{ .sym_index = sym_index, .file = null };1501 const sym_loc = SymbolWithLoc{ .sym_index = sym_index, .file = null };
1503 const sym = self.getSymbolPtr(sym_loc);1502 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));
1505 sym.value = decl_sym.value;1504 sym.value = decl_sym.value;
1506 sym.section_number = @intToEnum(coff.SectionNumber, self.text_section_index.? + 1);1505 sym.section_number = @intToEnum(coff.SectionNumber, self.text_section_index.? + 1);
1507 sym.type = .{ .complex_type = .FUNCTION, .base_type = .NULL };1506 sym.type = .{ .complex_type = .FUNCTION, .base_type = .NULL };
15081507
1509 switch (exp.linkage) {1508 switch (exp.opts.linkage) {
1510 .Strong => {1509 .Strong => {
1511 sym.storage_class = .EXTERNAL;1510 sym.storage_class = .EXTERNAL;
1512 },1511 },
src/link/Elf.zig+4-4
...@@ -2879,9 +2879,9 @@ pub fn updateDeclExports(...@@ -2879,9 +2879,9 @@ pub fn updateDeclExports(
2879 try self.global_symbols.ensureUnusedCapacity(gpa, exports.len);2879 try self.global_symbols.ensureUnusedCapacity(gpa, exports.len);
28802880
2881 for (exports) |exp| {2881 for (exports) |exp| {
2882 const exp_name = mod.intern_pool.stringToSlice(exp.name);2882 const exp_name = mod.intern_pool.stringToSlice(exp.opts.name);
2883 if (mod.intern_pool.stringToSliceUnwrap(exp.section)) |section_name| {2883 if (exp.opts.section.unwrap()) |section_name| {
2884 if (!mem.eql(u8, section_name, ".text")) {2884 if (!mod.intern_pool.stringEqlSlice(section_name, ".text")) {
2885 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);2885 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);
2886 mod.failed_exports.putAssumeCapacityNoClobber(2886 mod.failed_exports.putAssumeCapacityNoClobber(
2887 exp,2887 exp,
...@@ -2890,7 +2890,7 @@ pub fn updateDeclExports(...@@ -2890,7 +2890,7 @@ pub fn updateDeclExports(
2890 continue;2890 continue;
2891 }2891 }
2892 }2892 }
2893 const stb_bits: u8 = switch (exp.linkage) {2893 const stb_bits: u8 = switch (exp.opts.linkage) {
2894 .Internal => elf.STB_LOCAL,2894 .Internal => elf.STB_LOCAL,
2895 .Strong => blk: {2895 .Strong => blk: {
2896 const entry_name = self.base.options.entry orelse "_start";2896 const entry_name = self.base.options.entry orelse "_start";
src/link/MachO.zig+6-6
...@@ -2401,15 +2401,15 @@ pub fn updateDeclExports(...@@ -2401,15 +2401,15 @@ pub fn updateDeclExports(
2401 const decl_metadata = self.decls.getPtr(decl_index).?;2401 const decl_metadata = self.decls.getPtr(decl_index).?;
24022402
2403 for (exports) |exp| {2403 for (exports) |exp| {
2404 const exp_name = try std.fmt.allocPrint(gpa, "_{s}", .{2404 const exp_name = try std.fmt.allocPrint(gpa, "_{}", .{
2405 mod.intern_pool.stringToSlice(exp.name),2405 exp.opts.name.fmt(&mod.intern_pool),
2406 });2406 });
2407 defer gpa.free(exp_name);2407 defer gpa.free(exp_name);
24082408
2409 log.debug("adding new export '{s}'", .{exp_name});2409 log.debug("adding new export '{s}'", .{exp_name});
24102410
2411 if (mod.intern_pool.stringToSliceUnwrap(exp.section)) |section_name| {2411 if (exp.opts.section.unwrap()) |section_name| {
2412 if (!mem.eql(u8, section_name, "__text")) {2412 if (!mod.intern_pool.stringEqlSlice(section_name, "__text")) {
2413 try mod.failed_exports.putNoClobber(2413 try mod.failed_exports.putNoClobber(
2414 mod.gpa,2414 mod.gpa,
2415 exp,2415 exp,
...@@ -2424,7 +2424,7 @@ pub fn updateDeclExports(...@@ -2424,7 +2424,7 @@ pub fn updateDeclExports(
2424 }2424 }
2425 }2425 }
24262426
2427 if (exp.linkage == .LinkOnce) {2427 if (exp.opts.linkage == .LinkOnce) {
2428 try mod.failed_exports.putNoClobber(2428 try mod.failed_exports.putNoClobber(
2429 mod.gpa,2429 mod.gpa,
2430 exp,2430 exp,
...@@ -2453,7 +2453,7 @@ pub fn updateDeclExports(...@@ -2453,7 +2453,7 @@ pub fn updateDeclExports(
2453 .n_value = decl_sym.n_value,2453 .n_value = decl_sym.n_value,
2454 };2454 };
24552455
2456 switch (exp.linkage) {2456 switch (exp.opts.linkage) {
2457 .Internal => {2457 .Internal => {
2458 // Symbol should be hidden, or in MachO lingo, private extern.2458 // Symbol should be hidden, or in MachO lingo, private extern.
2459 // We should also mark the symbol as Weak: n_desc == N_WEAK_DEF.2459 // 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(...@@ -725,10 +725,10 @@ fn addDeclExports(
725 const decl_block = self.getDeclBlock(metadata.index);725 const decl_block = self.getDeclBlock(metadata.index);
726726
727 for (exports) |exp| {727 for (exports) |exp| {
728 const exp_name = mod.intern_pool.stringToSlice(exp.name);728 const exp_name = mod.intern_pool.stringToSlice(exp.opts.name);
729 // plan9 does not support custom sections729 // plan9 does not support custom sections
730 if (mod.intern_pool.stringToSliceUnwrap(exp.section)) |section_name| {730 if (exp.opts.section.unwrap()) |section_name| {
731 if (!mem.eql(u8, section_name, ".text") or !mem.eql(u8, section_name, ".data")) {731 if (!mod.intern_pool.stringEqlSlice(section_name, ".text") and !mod.intern_pool.stringEqlSlice(section_name, ".data")) {
732 try mod.failed_exports.put(mod.gpa, exp, try Module.ErrorMsg.create(732 try mod.failed_exports.put(mod.gpa, exp, try Module.ErrorMsg.create(
733 self.base.allocator,733 self.base.allocator,
734 mod.declPtr(decl_index).srcLoc(mod),734 mod.declPtr(decl_index).srcLoc(mod),
...@@ -972,7 +972,7 @@ pub fn writeSyms(self: *Plan9, buf: *std.ArrayList(u8)) !void {...@@ -972,7 +972,7 @@ pub fn writeSyms(self: *Plan9, buf: *std.ArrayList(u8)) !void {
972 const sym = self.syms.items[decl_block.sym_index.?];972 const sym = self.syms.items[decl_block.sym_index.?];
973 try self.writeSym(writer, sym);973 try self.writeSym(writer, sym);
974 if (self.base.options.module.?.decl_exports.get(decl_index)) |exports| {974 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| {
976 try self.writeSym(writer, self.syms.items[exp_i]);976 try self.writeSym(writer, self.syms.items[exp_i]);
977 };977 };
978 }978 }
...@@ -998,7 +998,7 @@ pub fn writeSyms(self: *Plan9, buf: *std.ArrayList(u8)) !void {...@@ -998,7 +998,7 @@ pub fn writeSyms(self: *Plan9, buf: *std.ArrayList(u8)) !void {
998 const sym = self.syms.items[decl_block.sym_index.?];998 const sym = self.syms.items[decl_block.sym_index.?];
999 try self.writeSym(writer, sym);999 try self.writeSym(writer, sym);
1000 if (self.base.options.module.?.decl_exports.get(decl_index)) |exports| {1000 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| {
1002 const s = self.syms.items[exp_i];1002 const s = self.syms.items[exp_i];
1003 if (mem.eql(u8, s.name, "_start"))1003 if (mem.eql(u8, s.name, "_start"))
1004 self.entry_val = s.value;1004 self.entry_val = s.value;
src/link/SpirV.zig+1-1
...@@ -147,7 +147,7 @@ pub fn updateDeclExports(...@@ -147,7 +147,7 @@ pub fn updateDeclExports(
147 const spv_decl_index = entry.value_ptr.*;147 const spv_decl_index = entry.value_ptr.*;
148148
149 for (exports) |exp| {149 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));
151 }151 }
152 }152 }
153153
src/link/Wasm.zig+7-7
...@@ -1706,7 +1706,7 @@ pub fn updateDeclExports(...@@ -1706,7 +1706,7 @@ pub fn updateDeclExports(
1706 const gpa = mod.gpa;1706 const gpa = mod.gpa;
17071707
1708 for (exports) |exp| {1708 for (exports) |exp| {
1709 if (mod.intern_pool.stringToSliceUnwrap(exp.section)) |section| {1709 if (mod.intern_pool.stringToSliceUnwrap(exp.opts.section)) |section| {
1710 try mod.failed_exports.putNoClobber(gpa, exp, try Module.ErrorMsg.create(1710 try mod.failed_exports.putNoClobber(gpa, exp, try Module.ErrorMsg.create(
1711 gpa,1711 gpa,
1712 decl.srcLoc(mod),1712 decl.srcLoc(mod),
...@@ -1716,12 +1716,12 @@ pub fn updateDeclExports(...@@ -1716,12 +1716,12 @@ pub fn updateDeclExports(
1716 continue;1716 continue;
1717 }1717 }
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));
1720 if (wasm.globals.getPtr(export_name)) |existing_loc| {1720 if (wasm.globals.getPtr(export_name)) |existing_loc| {
1721 if (existing_loc.index == atom.sym_index) continue;1721 if (existing_loc.index == atom.sym_index) continue;
1722 const existing_sym: Symbol = existing_loc.getSymbol(wasm).*;1722 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;
1725 // When both the to-be-exported symbol and the already existing symbol1725 // When both the to-be-exported symbol and the already existing symbol
1726 // are strong symbols, we have a linker error.1726 // are strong symbols, we have a linker error.
1727 // In the other case we replace one with the other.1727 // In the other case we replace one with the other.
...@@ -1729,11 +1729,11 @@ pub fn updateDeclExports(...@@ -1729,11 +1729,11 @@ pub fn updateDeclExports(
1729 try mod.failed_exports.put(gpa, exp, try Module.ErrorMsg.create(1729 try mod.failed_exports.put(gpa, exp, try Module.ErrorMsg.create(
1730 gpa,1730 gpa,
1731 decl.srcLoc(mod),1731 decl.srcLoc(mod),
1732 \\LinkError: symbol '{s}' defined multiple times1732 \\LinkError: symbol '{}' defined multiple times
1733 \\ first definition in '{s}'1733 \\ first definition in '{s}'
1734 \\ next definition in '{s}'1734 \\ next definition in '{s}'
1735 ,1735 ,
1736 .{ mod.intern_pool.stringToSlice(exp.name), wasm.name, wasm.name },1736 .{ exp.opts.name.fmt(&mod.intern_pool), wasm.name, wasm.name },
1737 ));1737 ));
1738 continue;1738 continue;
1739 } else if (exp_is_weak) {1739 } else if (exp_is_weak) {
...@@ -1750,7 +1750,7 @@ pub fn updateDeclExports(...@@ -1750,7 +1750,7 @@ pub fn updateDeclExports(
1750 const exported_atom = wasm.getAtom(exported_atom_index);1750 const exported_atom = wasm.getAtom(exported_atom_index);
1751 const sym_loc = exported_atom.symbolLoc();1751 const sym_loc = exported_atom.symbolLoc();
1752 const symbol = sym_loc.getSymbol(wasm);1752 const symbol = sym_loc.getSymbol(wasm);
1753 switch (exp.linkage) {1753 switch (exp.opts.linkage) {
1754 .Internal => {1754 .Internal => {
1755 symbol.setFlag(.WASM_SYM_VISIBILITY_HIDDEN);1755 symbol.setFlag(.WASM_SYM_VISIBILITY_HIDDEN);
1756 },1756 },
...@@ -1769,7 +1769,7 @@ pub fn updateDeclExports(...@@ -1769,7 +1769,7 @@ pub fn updateDeclExports(
1769 },1769 },
1770 }1770 }
1771 // Ensure the symbol will be exported using the given name1771 // 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))) {
1773 try wasm.export_names.put(wasm.base.allocator, sym_loc, export_name);1773 try wasm.export_names.put(wasm.base.allocator, sym_loc, export_name);
1774 }1774 }
17751775
src/print_air.zig+1-2
...@@ -685,9 +685,8 @@ const Writer = struct {...@@ -685,9 +685,8 @@ const Writer = struct {
685 fn writeDbgInline(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {685 fn writeDbgInline(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
686 const ty_fn = w.air.instructions.items(.data)[inst].ty_fn;686 const ty_fn = w.air.instructions.items(.data)[inst].ty_fn;
687 const func_index = ty_fn.func;687 const func_index = ty_fn.func;
688 const ip = &w.module.intern_pool;
689 const owner_decl = w.module.declPtr(w.module.funcPtr(func_index).owner_decl);688 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)});
691 }690 }
692691
693 fn writeDbgVar(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {692 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 {...@@ -284,7 +284,7 @@ pub const Type = struct {
284 try writer.writeAll("error{");284 try writer.writeAll("error{");
285 for (names, 0..) |name, i| {285 for (names, 0..) |name, i| {
286 if (i != 0) try writer.writeByte(',');286 if (i != 0) try writer.writeByte(',');
287 try writer.writeAll(mod.intern_pool.stringToSlice(name));287 try writer.print("{}", .{name.fmt(&mod.intern_pool)});
288 }288 }
289 try writer.writeAll("}");289 try writer.writeAll("}");
290 },290 },
...@@ -341,7 +341,7 @@ pub const Type = struct {...@@ -341,7 +341,7 @@ pub const Type = struct {
341 try decl.renderFullyQualifiedName(mod, writer);341 try decl.renderFullyQualifiedName(mod, writer);
342 } else if (struct_type.namespace.unwrap()) |namespace_index| {342 } else if (struct_type.namespace.unwrap()) |namespace_index| {
343 const namespace = mod.namespacePtr(namespace_index);343 const namespace = mod.namespacePtr(namespace_index);
344 try namespace.renderFullyQualifiedName(mod, "", writer);344 try namespace.renderFullyQualifiedName(mod, .empty, writer);
345 } else {345 } else {
346 try writer.writeAll("@TypeOf(.{})");346 try writer.writeAll("@TypeOf(.{})");
347 }347 }
...@@ -357,9 +357,7 @@ pub const Type = struct {...@@ -357,9 +357,7 @@ pub const Type = struct {
357 try writer.writeAll("comptime ");357 try writer.writeAll("comptime ");
358 }358 }
359 if (anon_struct.names.len != 0) {359 if (anon_struct.names.len != 0) {
360 const name = mod.intern_pool.stringToSlice(anon_struct.names[i]);360 try writer.print("{}: ", .{anon_struct.names[i].fmt(&mod.intern_pool)});
361 try writer.writeAll(name);
362 try writer.writeAll(": ");
363 }361 }
364362
365 try print(field_ty.toType(), writer, mod);363 try print(field_ty.toType(), writer, mod);
src/value.zig+9-36
...@@ -525,23 +525,6 @@ pub const Value = struct {...@@ -525,23 +525,6 @@ pub const Value = struct {
525 };525 };
526 }526 }
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
545 /// Asserts the value is an integer.528 /// Asserts the value is an integer.
546 pub fn toBigInt(val: Value, space: *BigIntSpace, mod: *Module) BigIntConst {529 pub fn toBigInt(val: Value, space: *BigIntSpace, mod: *Module) BigIntConst {
547 return val.toBigIntAdvanced(space, mod, null) catch unreachable;530 return val.toBigIntAdvanced(space, mod, null) catch unreachable;
...@@ -2092,33 +2075,23 @@ pub const Value = struct {...@@ -2092,33 +2075,23 @@ pub const Value = struct {
2092 };2075 };
2093 }2076 }
20942077
2095 /// Valid only for error (union) types. Asserts the value is not undefined and not2078 /// Valid only for error (union) types. Asserts the value is not undefined and not unreachable.
2096 /// unreachable. For error unions, prefer `errorUnionIsPayload` to find out whether2079 pub fn getErrorName(val: Value, mod: *const Module) InternPool.OptionalNullTerminatedString {
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 {
2107 return switch (mod.intern_pool.indexToKey(val.toIntern())) {2080 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
2108 .err => |err| err.name,2081 .err => |err| err.name.toOptional(),
2109 .error_union => |error_union| switch (error_union.val) {2082 .error_union => |error_union| switch (error_union.val) {
2110 .err_name => |err_name| err_name,2083 .err_name => |err_name| err_name.toOptional(),
2111 .payload => .empty,2084 .payload => .none,
2112 },2085 },
2113 else => unreachable,2086 else => unreachable,
2114 };2087 };
2115 }2088 }
21162089
2117 pub fn getErrorInt(val: Value, mod: *const Module) Module.ErrorInt {2090 pub fn getErrorInt(val: Value, mod: *const Module) Module.ErrorInt {
2118 return switch (getErrorName(val, mod)) {2091 return if (getErrorName(val, mod).unwrap()) |err_name|
2119 .empty => 0,2092 @intCast(Module.ErrorInt, mod.global_error_set.getIndex(err_name).?)
2120 else => |s| @intCast(Module.ErrorInt, mod.global_error_set.getIndex(s).?),2093 else
2121 };2094 0;
2122 }2095 }
21232096
2124 /// Assumes the type is an error union. Returns true if and only if the value is2097 /// Assumes the type is an error union. Returns true if and only if the value is