authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-02-22 18:33:36+01:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-02-22 19:10:52+01:00
log69a6f31596647fa0fca12346edb69dbe5bbc703a
treee01337b2dd4dbe7e7fc95898ba595d51cbc613a6
parent6cc51d3c3311a5d37401ec141424b30f57f62693

Builder: fix llvm ir value names

Hello world now verifies when not stripped.

3 files changed, 229 insertions(+), 188 deletions(-)

lib/std/meta.zig+2-1
...@@ -464,7 +464,8 @@ pub fn fieldNames(comptime T: type) *const [fields(T).len][:0]const u8 {...@@ -464,7 +464,8 @@ pub fn fieldNames(comptime T: type) *const [fields(T).len][:0]const u8 {
464 return comptime blk: {464 return comptime blk: {
465 const fieldInfos = fields(T);465 const fieldInfos = fields(T);
466 var names: [fieldInfos.len][:0]const u8 = undefined;466 var names: [fieldInfos.len][:0]const u8 = undefined;
467 for (&names, fieldInfos) |*name, field| name.* = field.name;467 // This concat can be removed with the next zig1 update.
468 for (&names, fieldInfos) |*name, field| name.* = field.name ++ "";
468 break :blk &names;469 break :blk &names;
469 };470 };
470}471}
src/codegen/llvm.zig+81-78
...@@ -849,51 +849,53 @@ pub const Object = struct {...@@ -849,51 +849,53 @@ pub const Object = struct {
849849
850 builder.data_layout = try builder.fmt("{}", .{DataLayoutBuilder{ .target = target }});850 builder.data_layout = try builder.fmt("{}", .{DataLayoutBuilder{ .target = target }});
851851
852 // We fully resolve all paths at this point to avoid lack of852 const debug_compile_unit, const debug_enums_fwd_ref, const debug_globals_fwd_ref =
853 // source line info in stack traces or lack of debugging853 if (!builder.strip)
854 // information which, if relative paths were used, would be854 debug_info: {
855 // very location dependent.855 // We fully resolve all paths at this point to avoid lack of
856 // TODO: the only concern I have with this is WASI as either host or target, should856 // source line info in stack traces or lack of debugging
857 // we leave the paths as relative then?857 // information which, if relative paths were used, would be
858 // TODO: This is totally wrong. In dwarf, paths are encoded as relative to858 // very location dependent.
859 // a particular directory, and then the directory path is specified elsewhere.859 // TODO: the only concern I have with this is WASI as either host or target, should
860 // In the compiler frontend we have it stored correctly in this860 // we leave the paths as relative then?
861 // way already, but here we throw all that sweet information861 // TODO: This is totally wrong. In dwarf, paths are encoded as relative to
862 // into the garbage can by converting into absolute paths. What862 // a particular directory, and then the directory path is specified elsewhere.
863 // a terrible tragedy.863 // In the compiler frontend we have it stored correctly in this
864 const compile_unit_dir = blk: {864 // way already, but here we throw all that sweet information
865 if (comp.module) |zcu| m: {865 // into the garbage can by converting into absolute paths. What
866 const d = try zcu.root_mod.root.joinString(arena, "");866 // a terrible tragedy.
867 if (d.len == 0) break :m;867 const compile_unit_dir = blk: {
868 if (std.fs.path.isAbsolute(d)) break :blk d;868 if (comp.module) |zcu| m: {
869 break :blk std.fs.realpathAlloc(arena, d) catch break :blk d;869 const d = try zcu.root_mod.root.joinString(arena, "");
870 }870 if (d.len == 0) break :m;
871 break :blk try std.process.getCwdAlloc(arena);871 if (std.fs.path.isAbsolute(d)) break :blk d;
872 };872 break :blk std.fs.realpathAlloc(arena, d) catch break :blk d;
873 }
874 break :blk try std.process.getCwdAlloc(arena);
875 };
873876
874 const debug_file = try builder.debugFile(877 const debug_file = try builder.debugFile(
875 try builder.metadataString(comp.root_name),878 try builder.metadataString(comp.root_name),
876 try builder.metadataString(compile_unit_dir),879 try builder.metadataString(compile_unit_dir),
877 );880 );
878881
879 const debug_enums_fwd_ref = try builder.debugForwardReference();882 const debug_enums_fwd_ref = try builder.debugForwardReference();
880 const debug_globals_fwd_ref = try builder.debugForwardReference();883 const debug_globals_fwd_ref = try builder.debugForwardReference();
881884
882 const debug_compile_unit = try builder.debugCompileUnit(885 const debug_compile_unit = try builder.debugCompileUnit(
883 debug_file,886 debug_file,
884 // Don't use the version string here; LLVM misparses it when it887 // Don't use the version string here; LLVM misparses it when it
885 // includes the git revision.888 // includes the git revision.
886 try builder.metadataStringFmt("zig {d}.{d}.{d}", .{889 try builder.metadataStringFmt("zig {d}.{d}.{d}", .{
887 build_options.semver.major,890 build_options.semver.major,
888 build_options.semver.minor,891 build_options.semver.minor,
889 build_options.semver.patch,892 build_options.semver.patch,
890 }),893 }),
891 debug_enums_fwd_ref,894 debug_enums_fwd_ref,
892 debug_globals_fwd_ref,895 debug_globals_fwd_ref,
893 .{ .optimized = comp.root_mod.optimize_mode != .Debug },896 .{ .optimized = comp.root_mod.optimize_mode != .Debug },
894 );897 );
895898
896 if (!builder.strip) {
897 const debug_info_version = try builder.debugModuleFlag(899 const debug_info_version = try builder.debugModuleFlag(
898 try builder.debugConstant(try builder.intConst(.i32, 2)),900 try builder.debugConstant(try builder.intConst(.i32, 2)),
899 try builder.metadataString("Debug Info Version"),901 try builder.metadataString("Debug Info Version"),
...@@ -901,6 +903,7 @@ pub const Object = struct {...@@ -901,6 +903,7 @@ pub const Object = struct {
901 );903 );
902904
903 switch (comp.config.debug_format) {905 switch (comp.config.debug_format) {
906 .strip => unreachable,
904 .dwarf => |f| {907 .dwarf => |f| {
905 const dwarf_version = try builder.debugModuleFlag(908 const dwarf_version = try builder.debugModuleFlag(
906 try builder.debugConstant(try builder.intConst(.i32, 2)),909 try builder.debugConstant(try builder.intConst(.i32, 2)),
...@@ -939,11 +942,11 @@ pub const Object = struct {...@@ -939,11 +942,11 @@ pub const Object = struct {
939 code_view,942 code_view,
940 });943 });
941 },944 },
942 .strip => unreachable,
943 }945 }
944946
945 try builder.debugNamed(try builder.metadataString("llvm.dbg.cu"), &.{debug_compile_unit});947 try builder.debugNamed(try builder.metadataString("llvm.dbg.cu"), &.{debug_compile_unit});
946 }948 break :debug_info .{ debug_compile_unit, debug_enums_fwd_ref, debug_globals_fwd_ref };
949 } else .{.none} ** 3;
947950
948 const obj = try arena.create(Object);951 const obj = try arena.create(Object);
949 obj.* = .{952 obj.* = .{
...@@ -1004,8 +1007,8 @@ pub const Object = struct {...@@ -1004,8 +1007,8 @@ pub const Object = struct {
10041007
1005 llvm_errors[0] = try o.builder.undefConst(llvm_slice_ty);1008 llvm_errors[0] = try o.builder.undefConst(llvm_slice_ty);
1006 for (llvm_errors[1..], error_name_list[1..]) |*llvm_error, name| {1009 for (llvm_errors[1..], error_name_list[1..]) |*llvm_error, name| {
1007 const name_string = try o.builder.string(mod.intern_pool.stringToSlice(name));1010 const name_string = try o.builder.stringNull(mod.intern_pool.stringToSlice(name));
1008 const name_init = try o.builder.stringNullConst(name_string);1011 const name_init = try o.builder.stringConst(name_string);
1009 const name_variable_index =1012 const name_variable_index =
1010 try o.builder.addVariable(.empty, name_init.typeOf(&o.builder), .default);1013 try o.builder.addVariable(.empty, name_init.typeOf(&o.builder), .default);
1011 try name_variable_index.setInitializer(name_init, &o.builder);1014 try name_variable_index.setInitializer(name_init, &o.builder);
...@@ -1016,7 +1019,7 @@ pub const Object = struct {...@@ -1016,7 +1019,7 @@ pub const Object = struct {
10161019
1017 llvm_error.* = try o.builder.structConst(llvm_slice_ty, &.{1020 llvm_error.* = try o.builder.structConst(llvm_slice_ty, &.{
1018 name_variable_index.toConst(&o.builder),1021 name_variable_index.toConst(&o.builder),
1019 try o.builder.intConst(llvm_usize_ty, name_string.slice(&o.builder).?.len),1022 try o.builder.intConst(llvm_usize_ty, name_string.slice(&o.builder).?.len - 1),
1020 });1023 });
1021 }1024 }
10221025
...@@ -1145,28 +1148,27 @@ pub const Object = struct {...@@ -1145,28 +1148,27 @@ pub const Object = struct {
1145 try self.genCmpLtErrorsLenFunction();1148 try self.genCmpLtErrorsLenFunction();
1146 try self.genModuleLevelAssembly();1149 try self.genModuleLevelAssembly();
11471150
1148 {1151 if (!self.builder.strip) {
1149 var i: usize = 0;1152 for (
1150 while (i < self.debug_unresolved_namespace_scopes.count()) : (i += 1) {1153 self.debug_unresolved_namespace_scopes.keys(),
1151 const namespace_index = self.debug_unresolved_namespace_scopes.keys()[i];1154 self.debug_unresolved_namespace_scopes.values(),
1152 const fwd_ref = self.debug_unresolved_namespace_scopes.values()[i];1155 ) |namespace_index, fwd_ref| {
1153 const namespace = self.module.namespacePtr(namespace_index);1156 const namespace = self.module.namespacePtr(namespace_index);
1154
1155 const debug_type = try self.lowerDebugType(namespace.ty);1157 const debug_type = try self.lowerDebugType(namespace.ty);
11561158
1157 self.builder.debugForwardReferenceSetType(fwd_ref, debug_type);1159 self.builder.debugForwardReferenceSetType(fwd_ref, debug_type);
1158 }1160 }
1159 }
11601161
1161 self.builder.debugForwardReferenceSetType(1162 self.builder.debugForwardReferenceSetType(
1162 self.debug_enums_fwd_ref,1163 self.debug_enums_fwd_ref,
1163 try self.builder.debugTuple(self.debug_enums.items),1164 try self.builder.debugTuple(self.debug_enums.items),
1164 );1165 );
11651166
1166 self.builder.debugForwardReferenceSetType(1167 self.builder.debugForwardReferenceSetType(
1167 self.debug_globals_fwd_ref,1168 self.debug_globals_fwd_ref,
1168 try self.builder.debugTuple(self.debug_globals.items),1169 try self.builder.debugTuple(self.debug_globals.items),
1169 );1170 );
1171 }
11701172
1171 if (options.pre_ir_path) |path| {1173 if (options.pre_ir_path) |path| {
1172 if (std.mem.eql(u8, path, "-")) {1174 if (std.mem.eql(u8, path, "-")) {
...@@ -1241,13 +1243,12 @@ pub const Object = struct {...@@ -1241,13 +1243,12 @@ pub const Object = struct {
1241 };1243 };
1242 bitcode_arena_allocator.deinit();1244 bitcode_arena_allocator.deinit();
12431245
1244 var error_message: [*:0]const u8 = undefined;1246 const target_triple_sentinel =
1247 try self.gpa.dupeZ(u8, self.builder.target_triple.slice(&self.builder).?);
1248 defer self.gpa.free(target_triple_sentinel);
1245 var target: *llvm.Target = undefined;1249 var target: *llvm.Target = undefined;
1246 if (llvm.Target.getFromTriple(1250 var error_message: [*:0]const u8 = undefined;
1247 self.builder.target_triple.slice(&self.builder).?,1251 if (llvm.Target.getFromTriple(target_triple_sentinel, &target, &error_message).toBool()) {
1248 &target,
1249 &error_message,
1250 ).toBool()) {
1251 defer llvm.disposeMessage(error_message);1252 defer llvm.disposeMessage(error_message);
12521253
1253 log.err("LLVM failed to parse '{s}': {s}", .{1254 log.err("LLVM failed to parse '{s}': {s}", .{
...@@ -1286,7 +1287,7 @@ pub const Object = struct {...@@ -1286,7 +1287,7 @@ pub const Object = struct {
12861287
1287 var target_machine = llvm.TargetMachine.create(1288 var target_machine = llvm.TargetMachine.create(
1288 target,1289 target,
1289 self.builder.target_triple.slice(&self.builder).?,1290 target_triple_sentinel,
1290 if (self.module.comp.root_mod.resolved_target.result.cpu.model.llvm_name) |s| s.ptr else null,1291 if (self.module.comp.root_mod.resolved_target.result.cpu.model.llvm_name) |s| s.ptr else null,
1291 self.module.comp.root_mod.resolved_target.llvm_cpu_features.?,1292 self.module.comp.root_mod.resolved_target.llvm_cpu_features.?,
1292 opt_level,1293 opt_level,
...@@ -1640,15 +1641,15 @@ pub const Object = struct {...@@ -1640,15 +1641,15 @@ pub const Object = struct {
16401641
1641 function_index.setAttributes(try attributes.finish(&o.builder), &o.builder);1642 function_index.setAttributes(try attributes.finish(&o.builder), &o.builder);
16421643
1643 const file = try o.getDebugFile(namespace.file_scope);1644 const file, const subprogram = if (!o.builder.strip) debug_info: {
1645 const file = try o.getDebugFile(namespace.file_scope);
16441646
1645 const subprogram = blk: {
1646 const line_number = decl.src_line + 1;1647 const line_number = decl.src_line + 1;
1647 const is_internal_linkage = decl.val.getExternFunc(zcu) == null and1648 const is_internal_linkage = decl.val.getExternFunc(zcu) == null and
1648 !zcu.decl_exports.contains(decl_index);1649 !zcu.decl_exports.contains(decl_index);
1649 const debug_decl_type = try o.lowerDebugType(decl.ty);1650 const debug_decl_type = try o.lowerDebugType(decl.ty);
16501651
1651 break :blk try o.builder.debugSubprogram(1652 const subprogram = try o.builder.debugSubprogram(
1652 file,1653 file,
1653 try o.builder.metadataString(ip.stringToSlice(decl.name)),1654 try o.builder.metadataString(ip.stringToSlice(decl.name)),
1654 try o.builder.metadataStringFromString(function_index.name(&o.builder)),1655 try o.builder.metadataStringFromString(function_index.name(&o.builder)),
...@@ -1668,8 +1669,9 @@ pub const Object = struct {...@@ -1668,8 +1669,9 @@ pub const Object = struct {
1668 },1669 },
1669 o.debug_compile_unit,1670 o.debug_compile_unit,
1670 );1671 );
1671 };1672 function_index.setSubprogram(subprogram, &o.builder);
1672 function_index.setSubprogram(subprogram, &o.builder);1673 break :debug_info .{ file, subprogram };
1674 } else .{.none} ** 2;
16731675
1674 var fg: FuncGen = .{1676 var fg: FuncGen = .{
1675 .gpa = gpa,1677 .gpa = gpa,
...@@ -1924,7 +1926,8 @@ pub const Object = struct {...@@ -1924,7 +1926,8 @@ pub const Object = struct {
1924 o: *Object,1926 o: *Object,
1925 ty: Type,1927 ty: Type,
1926 ) Allocator.Error!Builder.Metadata {1928 ) Allocator.Error!Builder.Metadata {
1927 if (o.builder.strip) return .none;1929 assert(!o.builder.strip);
1930
1928 const gpa = o.gpa;1931 const gpa = o.gpa;
1929 const target = o.target;1932 const target = o.target;
1930 const mod = o.module;1933 const mod = o.module;
...@@ -4608,8 +4611,8 @@ pub const Object = struct {...@@ -4608,8 +4611,8 @@ pub const Object = struct {
4608 defer wip_switch.finish(&wip);4611 defer wip_switch.finish(&wip);
46094612
4610 for (0..enum_type.names.len) |field_index| {4613 for (0..enum_type.names.len) |field_index| {
4611 const name = try o.builder.string(ip.stringToSlice(enum_type.names.get(ip)[field_index]));4614 const name = try o.builder.stringNull(ip.stringToSlice(enum_type.names.get(ip)[field_index]));
4612 const name_init = try o.builder.stringNullConst(name);4615 const name_init = try o.builder.stringConst(name);
4613 const name_variable_index =4616 const name_variable_index =
4614 try o.builder.addVariable(.empty, name_init.typeOf(&o.builder), .default);4617 try o.builder.addVariable(.empty, name_init.typeOf(&o.builder), .default);
4615 try name_variable_index.setInitializer(name_init, &o.builder);4618 try name_variable_index.setInitializer(name_init, &o.builder);
...@@ -4620,7 +4623,7 @@ pub const Object = struct {...@@ -4620,7 +4623,7 @@ pub const Object = struct {
46204623
4621 const name_val = try o.builder.structValue(ret_ty, &.{4624 const name_val = try o.builder.structValue(ret_ty, &.{
4622 name_variable_index.toConst(&o.builder),4625 name_variable_index.toConst(&o.builder),
4623 try o.builder.intConst(usize_ty, name.slice(&o.builder).?.len),4626 try o.builder.intConst(usize_ty, name.slice(&o.builder).?.len - 1),
4624 });4627 });
46254628
4626 const return_block = try wip.block(1, "Name");4629 const return_block = try wip.block(1, "Name");
src/codegen/llvm/Builder.zig+146-109
...@@ -77,11 +77,11 @@ pub const String = enum(u32) {...@@ -77,11 +77,11 @@ pub const String = enum(u32) {
77 return self.toIndex() == null;77 return self.toIndex() == null;
78 }78 }
7979
80 pub fn slice(self: String, builder: *const Builder) ?[:0]const u8 {80 pub fn slice(self: String, builder: *const Builder) ?[]const u8 {
81 const index = self.toIndex() orelse return null;81 const index = self.toIndex() orelse return null;
82 const start = builder.string_indices.items[index];82 const start = builder.string_indices.items[index];
83 const end = builder.string_indices.items[index + 1];83 const end = builder.string_indices.items[index + 1];
84 return builder.string_bytes.items[start .. end - 1 :0];84 return builder.string_bytes.items[start..end];
85 }85 }
8686
87 const FormatData = struct {87 const FormatData = struct {
...@@ -94,17 +94,21 @@ pub const String = enum(u32) {...@@ -94,17 +94,21 @@ pub const String = enum(u32) {
94 _: std.fmt.FormatOptions,94 _: std.fmt.FormatOptions,
95 writer: anytype,95 writer: anytype,
96 ) @TypeOf(writer).Error!void {96 ) @TypeOf(writer).Error!void {
97 if (comptime std.mem.indexOfNone(u8, fmt_str, "@\"")) |_|97 if (comptime std.mem.indexOfNone(u8, fmt_str, "\"r")) |_|
98 @compileError("invalid format string: '" ++ fmt_str ++ "'");98 @compileError("invalid format string: '" ++ fmt_str ++ "'");
99 assert(data.string != .none);99 assert(data.string != .none);
100 const sentinel_slice = data.string.slice(data.builder) orelse100 const string_slice = data.string.slice(data.builder) orelse
101 return writer.print("{d}", .{@intFromEnum(data.string)});101 return writer.print("{d}", .{@intFromEnum(data.string)});
102 try printEscapedString(sentinel_slice[0 .. sentinel_slice.len + comptime @intFromBool(102 if (comptime std.mem.indexOfScalar(u8, fmt_str, 'r')) |_|
103 std.mem.indexOfScalar(u8, fmt_str, '@') != null,103 return writer.writeAll(string_slice);
104 )], if (comptime std.mem.indexOfScalar(u8, fmt_str, '"')) |_|104 try printEscapedString(
105 .always_quote105 string_slice,
106 else106 if (comptime std.mem.indexOfScalar(u8, fmt_str, '"')) |_|
107 .quote_unless_valid_identifier, writer);107 .always_quote
108 else
109 .quote_unless_valid_identifier,
110 writer,
111 );
108 }112 }
109 pub fn fmt(self: String, builder: *const Builder) std.fmt.Formatter(format) {113 pub fn fmt(self: String, builder: *const Builder) std.fmt.Formatter(format) {
110 return .{ .data = .{ .string = self, .builder = builder } };114 return .{ .data = .{ .string = self, .builder = builder } };
...@@ -4597,13 +4601,6 @@ pub const Function = struct {...@@ -4597,13 +4601,6 @@ pub const Function = struct {
4597 ) std.fmt.Formatter(format) {4601 ) std.fmt.Formatter(format) {
4598 return .{ .data = .{ .instruction = self, .function = function, .builder = builder } };4602 return .{ .data = .{ .instruction = self, .function = function, .builder = builder } };
4599 }4603 }
4600
4601 fn llvmName(self: Instruction.Index, wip: *const WipFunction) [:0]const u8 {
4602 return if (wip.builder.strip)
4603 ""
4604 else
4605 wip.names.items[@intFromEnum(self)].slice(wip.builder).?;
4606 }
4607 };4604 };
46084605
4609 pub const ExtraIndex = u32;4606 pub const ExtraIndex = u32;
...@@ -5931,15 +5928,47 @@ pub const WipFunction = struct {...@@ -5931,15 +5928,47 @@ pub const WipFunction = struct {
59315928
5932 var wip_name: struct {5929 var wip_name: struct {
5933 next_name: String = @enumFromInt(0),5930 next_name: String = @enumFromInt(0),
5931 next_unique_name: std.AutoHashMap(String, String),
5932 builder: *Builder,
59345933
5935 fn map(wip_name: *@This(), old_name: String) String {5934 fn map(wip_name: *@This(), name: String, sep: []const u8) Allocator.Error!String {
5936 if (old_name != .empty) return old_name;5935 switch (name) {
5936 .none => return .none,
5937 .empty => {
5938 assert(wip_name.next_name != .none);
5939 defer wip_name.next_name = @enumFromInt(@intFromEnum(wip_name.next_name) + 1);
5940 return wip_name.next_name;
5941 },
5942 _ => {
5943 assert(!name.isAnon());
5944 const gop = try wip_name.next_unique_name.getOrPut(name);
5945 if (!gop.found_existing) {
5946 gop.value_ptr.* = @enumFromInt(0);
5947 return name;
5948 }
59375949
5938 const new_name = wip_name.next_name;5950 while (true) {
5939 wip_name.next_name = @enumFromInt(@intFromEnum(new_name) + 1);5951 gop.value_ptr.* = @enumFromInt(@intFromEnum(gop.value_ptr.*) + 1);
5940 return new_name;5952 const unique_name = try wip_name.builder.fmt("{r}{s}{r}", .{
5953 name.fmt(wip_name.builder),
5954 sep,
5955 gop.value_ptr.fmt(wip_name.builder),
5956 });
5957 const unique_gop = try wip_name.next_unique_name.getOrPut(unique_name);
5958 if (!unique_gop.found_existing) {
5959 unique_gop.value_ptr.* = @enumFromInt(0);
5960 return unique_name;
5961 }
5962 }
5963 },
5964 }
5941 }5965 }
5942 } = .{};5966 } = .{
5967 .next_unique_name = std.AutoHashMap(String, String).init(gpa),
5968 .builder = self.builder,
5969 };
5970 defer wip_name.next_unique_name.deinit();
5971
5943 var value_index: u32 = 0;5972 var value_index: u32 = 0;
5944 for (0..params_len) |param_index| {5973 for (0..params_len) |param_index| {
5945 const old_argument_index: Instruction.Index = @enumFromInt(param_index);5974 const old_argument_index: Instruction.Index = @enumFromInt(param_index);
...@@ -5950,8 +5979,9 @@ pub const WipFunction = struct {...@@ -5950,8 +5979,9 @@ pub const WipFunction = struct {
5950 value_indices[function.instructions.len] = value_index;5979 value_indices[function.instructions.len] = value_index;
5951 value_index += 1;5980 value_index += 1;
5952 function.instructions.appendAssumeCapacity(argument);5981 function.instructions.appendAssumeCapacity(argument);
5953 names[@intFromEnum(new_argument_index)] = wip_name.map(5982 names[@intFromEnum(new_argument_index)] = try wip_name.map(
5954 if (self.builder.strip) .empty else self.names.items[@intFromEnum(old_argument_index)],5983 if (self.builder.strip) .empty else self.names.items[@intFromEnum(old_argument_index)],
5984 ".",
5955 );5985 );
5956 if (self.debug_locations.get(old_argument_index)) |location| {5986 if (self.debug_locations.get(old_argument_index)) |location| {
5957 debug_locations.putAssumeCapacity(new_argument_index, location);5987 debug_locations.putAssumeCapacity(new_argument_index, location);
...@@ -5967,7 +5997,7 @@ pub const WipFunction = struct {...@@ -5967,7 +5997,7 @@ pub const WipFunction = struct {
5967 .tag = .block,5997 .tag = .block,
5968 .data = current_block.incoming,5998 .data = current_block.incoming,
5969 });5999 });
5970 names[@intFromEnum(new_block_index)] = wip_name.map(current_block.name);6000 names[@intFromEnum(new_block_index)] = try wip_name.map(current_block.name, "");
5971 for (current_block.instructions.items) |old_instruction_index| {6001 for (current_block.instructions.items) |old_instruction_index| {
5972 const new_instruction_index: Instruction.Index =6002 const new_instruction_index: Instruction.Index =
5973 @enumFromInt(function.instructions.len);6003 @enumFromInt(function.instructions.len);
...@@ -6268,10 +6298,10 @@ pub const WipFunction = struct {...@@ -6268,10 +6298,10 @@ pub const WipFunction = struct {
6268 },6298 },
6269 }6299 }
6270 function.instructions.appendAssumeCapacity(instruction);6300 function.instructions.appendAssumeCapacity(instruction);
6271 names[@intFromEnum(new_instruction_index)] = wip_name.map(if (self.builder.strip)6301 names[@intFromEnum(new_instruction_index)] = try wip_name.map(if (self.builder.strip)
6272 if (old_instruction_index.hasResultWip(self)) .empty else .none6302 if (old_instruction_index.hasResultWip(self)) .empty else .none
6273 else6303 else
6274 self.names.items[@intFromEnum(old_instruction_index)]);6304 self.names.items[@intFromEnum(old_instruction_index)], ".");
62756305
6276 if (self.debug_locations.get(old_instruction_index)) |location| {6306 if (self.debug_locations.get(old_instruction_index)) |location| {
6277 debug_locations.putAssumeCapacity(new_instruction_index, location);6307 debug_locations.putAssumeCapacity(new_instruction_index, location);
...@@ -6687,7 +6717,6 @@ pub const Constant = enum(u32) {...@@ -6687,7 +6717,6 @@ pub const Constant = enum(u32) {
6687 packed_structure,6717 packed_structure,
6688 array,6718 array,
6689 string,6719 string,
6690 string_null,
6691 vector,6720 vector,
6692 splat,6721 splat,
6693 zeroinitializer,6722 zeroinitializer,
...@@ -6943,10 +6972,8 @@ pub const Constant = enum(u32) {...@@ -6943,10 +6972,8 @@ pub const Constant = enum(u32) {
6943 => builder.constantExtraData(Aggregate, item.data).type,6972 => builder.constantExtraData(Aggregate, item.data).type,
6944 .splat => builder.constantExtraData(Splat, item.data).type,6973 .splat => builder.constantExtraData(Splat, item.data).type,
6945 .string,6974 .string,
6946 .string_null,
6947 => builder.arrayTypeAssumeCapacity(6975 => builder.arrayTypeAssumeCapacity(
6948 @as(String, @enumFromInt(item.data)).slice(builder).?.len +6976 @as(String, @enumFromInt(item.data)).slice(builder).?.len,
6949 @intFromBool(item.tag == .string_null),
6950 .i8,6977 .i8,
6951 ),6978 ),
6952 .blockaddress => builder.ptrTypeAssumeCapacity(6979 .blockaddress => builder.ptrTypeAssumeCapacity(
...@@ -7281,13 +7308,9 @@ pub const Constant = enum(u32) {...@@ -7281,13 +7308,9 @@ pub const Constant = enum(u32) {
7281 }7308 }
7282 try writer.writeByte('>');7309 try writer.writeByte('>');
7283 },7310 },
7284 inline .string,7311 .string => try writer.print("c{\"}", .{
7285 .string_null,7312 @as(String, @enumFromInt(item.data)).fmt(data.builder),
7286 => |tag| try writer.print("c{\"" ++ switch (tag) {7313 }),
7287 .string => "",
7288 .string_null => "@",
7289 else => unreachable,
7290 } ++ "}", .{@as(String, @enumFromInt(item.data)).fmt(data.builder)}),
7291 .blockaddress => |tag| {7314 .blockaddress => |tag| {
7292 const extra = data.builder.constantExtraData(BlockAddress, item.data);7315 const extra = data.builder.constantExtraData(BlockAddress, item.data);
7293 const function = extra.function.ptrConst(data.builder);7316 const function = extra.function.ptrConst(data.builder);
...@@ -7658,7 +7681,7 @@ pub const Metadata = enum(u32) {...@@ -7658,7 +7681,7 @@ pub const Metadata = enum(u32) {
7658 {7681 {
7659 const index = @intFromEnum(metadata) - Metadata.first_forward_reference;7682 const index = @intFromEnum(metadata) - Metadata.first_forward_reference;
7660 metadata = builder.metadata_forward_references.items[index];7683 metadata = builder.metadata_forward_references.items[index];
7661 std.debug.assert(metadata != .none);7684 assert(metadata != .none);
7662 }7685 }
7663 return metadata;7686 return metadata;
7664 }7687 }
...@@ -8058,30 +8081,33 @@ pub const Metadata = enum(u32) {...@@ -8058,30 +8081,33 @@ pub const Metadata = enum(u32) {
8058 }8081 }
8059 },8082 },
8060 .index => |item| try writer.print("!{d}", .{item}),8083 .index => |item| try writer.print("!{d}", .{item}),
8061 .value => |item| try Value.format(.{8084 .value => |item| switch (item.value.unwrap()) {
8062 .value = switch (item.value.unwrap()) {8085 .instruction, .constant => try Value.format(.{
8063 .instruction, .constant => item.value,8086 .value = item.value,
8064 .metadata => |metadata| if (@intFromEnum(metadata) >=8087 .function = item.function,
8065 Metadata.first_local_metadata)8088 .builder = builder,
8066 item.function.ptrConst(builder).debug_values[8089 }, fmt_str, fmt_opts, writer),
8090 .metadata => |metadata| if (@intFromEnum(metadata) >=
8091 Metadata.first_local_metadata)
8092 try Value.format(.{
8093 .value = item.function.ptrConst(builder).debug_values[
8067 @intFromEnum(metadata) - Metadata.first_local_metadata8094 @intFromEnum(metadata) - Metadata.first_local_metadata
8068 ].toValue()8095 ].toValue(),
8069 else if (metadata != .none) {8096 .function = item.function,
8070 if (comptime std.mem.eql(u8, fmt_str, "%"))8097 .builder = builder,
8071 try writer.print("{%} ", .{Type.metadata.fmt(builder)});8098 }, "%", fmt_opts, writer)
8072 try Metadata.Formatter.format(.{8099 else if (metadata != .none) {
8073 .formatter = data.formatter,8100 if (comptime std.mem.eql(u8, fmt_str, "%"))
8074 .item = data.formatter.unwrapAssumeExists(metadata),8101 try writer.print("{%} ", .{Type.metadata.fmt(builder)});
8075 }, "", fmt_opts, writer);8102 try Metadata.Formatter.format(.{
8076 return;8103 .formatter = data.formatter,
8077 } else return,8104 .item = data.formatter.unwrapAssumeExists(metadata),
8105 }, "", fmt_opts, writer);
8078 },8106 },
8079 .function = item.function,8107 },
8080 .builder = builder,
8081 }, "%", fmt_opts, writer),
8082 .string => |item| try writer.print("{}", .{item.fmt(data.formatter.builder)}),8108 .string => |item| try writer.print("{}", .{item.fmt(data.formatter.builder)}),
8083 inline .bool, .u32, .u64 => |item| try writer.print("{}", .{item}),8109 inline .bool, .u32, .u64 => |item| try writer.print("{}", .{item}),
8084 .raw => |item| try writer.print("{s}", .{item}),8110 .raw => |item| try writer.writeAll(item),
8085 }8111 }
8086 }8112 }
8087 inline fn fmt(formatter: *Formatter, prefix: []const u8, item: anytype) switch (@TypeOf(item)) {8113 inline fn fmt(formatter: *Formatter, prefix: []const u8, item: anytype) switch (@TypeOf(item)) {
...@@ -8188,7 +8214,7 @@ pub const Metadata = enum(u32) {...@@ -8188,7 +8214,7 @@ pub const Metadata = enum(u32) {
8188 inline for (fields[2..], names) |*field, name| {8214 inline for (fields[2..], names) |*field, name| {
8189 fmt_str = fmt_str ++ "{[" ++ name ++ "]}";8215 fmt_str = fmt_str ++ "{[" ++ name ++ "]}";
8190 field.* = .{8216 field.* = .{
8191 .name = name ++ "",8217 .name = name,
8192 .type = std.fmt.Formatter(format),8218 .type = std.fmt.Formatter(format),
8193 .default_value = null,8219 .default_value = null,
8194 .is_comptime = false,8220 .is_comptime = false,
...@@ -8305,7 +8331,7 @@ pub fn init(options: Options) Allocator.Error!Builder {...@@ -8305,7 +8331,7 @@ pub fn init(options: Options) Allocator.Error!Builder {
8305 assert(try self.intConst(.i1, 0) == .false);8331 assert(try self.intConst(.i1, 0) == .false);
8306 assert(try self.intConst(.i1, 1) == .true);8332 assert(try self.intConst(.i1, 1) == .true);
8307 assert(try self.noneConst(.token) == .none);8333 assert(try self.noneConst(.token) == .none);
8308 assert(try self.debugNone() == .none);8334 if (!self.strip) assert(try self.debugNone() == .none);
83098335
8310 try self.metadata_string_indices.append(self.gpa, 0);8336 try self.metadata_string_indices.append(self.gpa, 0);
8311 assert(try self.metadataString("") == .none);8337 assert(try self.metadataString("") == .none);
...@@ -8374,19 +8400,22 @@ pub fn finishModuleAsm(self: *Builder) Allocator.Error!void {...@@ -8374,19 +8400,22 @@ pub fn finishModuleAsm(self: *Builder) Allocator.Error!void {
8374}8400}
83758401
8376pub fn string(self: *Builder, bytes: []const u8) Allocator.Error!String {8402pub fn string(self: *Builder, bytes: []const u8) Allocator.Error!String {
8377 try self.string_bytes.ensureUnusedCapacity(self.gpa, bytes.len + 1);8403 try self.string_bytes.ensureUnusedCapacity(self.gpa, bytes.len);
8378 try self.string_indices.ensureUnusedCapacity(self.gpa, 1);8404 try self.string_indices.ensureUnusedCapacity(self.gpa, 1);
8379 try self.string_map.ensureUnusedCapacity(self.gpa, 1);8405 try self.string_map.ensureUnusedCapacity(self.gpa, 1);
83808406
8381 const gop = self.string_map.getOrPutAssumeCapacityAdapted(bytes, String.Adapter{ .builder = self });8407 const gop = self.string_map.getOrPutAssumeCapacityAdapted(bytes, String.Adapter{ .builder = self });
8382 if (!gop.found_existing) {8408 if (!gop.found_existing) {
8383 self.string_bytes.appendSliceAssumeCapacity(bytes);8409 self.string_bytes.appendSliceAssumeCapacity(bytes);
8384 self.string_bytes.appendAssumeCapacity(0);
8385 self.string_indices.appendAssumeCapacity(@intCast(self.string_bytes.items.len));8410 self.string_indices.appendAssumeCapacity(@intCast(self.string_bytes.items.len));
8386 }8411 }
8387 return String.fromIndex(gop.index);8412 return String.fromIndex(gop.index);
8388}8413}
83898414
8415pub fn stringNull(self: *Builder, bytes: [:0]const u8) Allocator.Error!String {
8416 return self.string(bytes[0 .. bytes.len + 1]);
8417}
8418
8390pub fn stringIfExists(self: *const Builder, bytes: []const u8) ?String {8419pub fn stringIfExists(self: *const Builder, bytes: []const u8) ?String {
8391 return String.fromIndex(8420 return String.fromIndex(
8392 self.string_map.getIndexAdapted(bytes, String.Adapter{ .builder = self }) orelse return null,8421 self.string_map.getIndexAdapted(bytes, String.Adapter{ .builder = self }) orelse return null,
...@@ -8395,15 +8424,15 @@ pub fn stringIfExists(self: *const Builder, bytes: []const u8) ?String {...@@ -8395,15 +8424,15 @@ pub fn stringIfExists(self: *const Builder, bytes: []const u8) ?String {
83958424
8396pub fn fmt(self: *Builder, comptime fmt_str: []const u8, fmt_args: anytype) Allocator.Error!String {8425pub fn fmt(self: *Builder, comptime fmt_str: []const u8, fmt_args: anytype) Allocator.Error!String {
8397 try self.string_map.ensureUnusedCapacity(self.gpa, 1);8426 try self.string_map.ensureUnusedCapacity(self.gpa, 1);
8398 try self.string_bytes.ensureUnusedCapacity(self.gpa, @intCast(std.fmt.count(fmt_str ++ .{0}, fmt_args)));8427 try self.string_bytes.ensureUnusedCapacity(self.gpa, @intCast(std.fmt.count(fmt_str, fmt_args)));
8399 try self.string_indices.ensureUnusedCapacity(self.gpa, 1);8428 try self.string_indices.ensureUnusedCapacity(self.gpa, 1);
8400 return self.fmtAssumeCapacity(fmt_str, fmt_args);8429 return self.fmtAssumeCapacity(fmt_str, fmt_args);
8401}8430}
84028431
8403pub fn fmtAssumeCapacity(self: *Builder, comptime fmt_str: []const u8, fmt_args: anytype) String {8432pub fn fmtAssumeCapacity(self: *Builder, comptime fmt_str: []const u8, fmt_args: anytype) String {
8404 const start = self.string_bytes.items.len;8433 const start = self.string_bytes.items.len;
8405 self.string_bytes.writer(self.gpa).print(fmt_str ++ .{0}, fmt_args) catch unreachable;8434 self.string_bytes.writer(undefined).print(fmt_str, fmt_args) catch unreachable;
8406 const bytes: []const u8 = self.string_bytes.items[start .. self.string_bytes.items.len - 1];8435 const bytes: []const u8 = self.string_bytes.items[start..];
84078436
8408 const gop = self.string_map.getOrPutAssumeCapacityAdapted(bytes, String.Adapter{ .builder = self });8437 const gop = self.string_map.getOrPutAssumeCapacityAdapted(bytes, String.Adapter{ .builder = self });
8409 if (gop.found_existing) {8438 if (gop.found_existing) {
...@@ -8468,7 +8497,7 @@ pub fn structType(...@@ -8468,7 +8497,7 @@ pub fn structType(
8468pub fn opaqueType(self: *Builder, name: String) Allocator.Error!Type {8497pub fn opaqueType(self: *Builder, name: String) Allocator.Error!Type {
8469 try self.string_map.ensureUnusedCapacity(self.gpa, 1);8498 try self.string_map.ensureUnusedCapacity(self.gpa, 1);
8470 if (name.slice(self)) |id| {8499 if (name.slice(self)) |id| {
8471 const count: usize = comptime std.fmt.count("{d}" ++ .{0}, .{std.math.maxInt(u32)});8500 const count: usize = comptime std.fmt.count("{d}", .{std.math.maxInt(u32)});
8472 try self.string_bytes.ensureUnusedCapacity(self.gpa, id.len + count);8501 try self.string_bytes.ensureUnusedCapacity(self.gpa, id.len + count);
8473 }8502 }
8474 try self.string_indices.ensureUnusedCapacity(self.gpa, 1);8503 try self.string_indices.ensureUnusedCapacity(self.gpa, 1);
...@@ -8911,16 +8940,6 @@ pub fn stringValue(self: *Builder, val: String) Allocator.Error!Value {...@@ -8911,16 +8940,6 @@ pub fn stringValue(self: *Builder, val: String) Allocator.Error!Value {
8911 return (try self.stringConst(val)).toValue();8940 return (try self.stringConst(val)).toValue();
8912}8941}
89138942
8914pub fn stringNullConst(self: *Builder, val: String) Allocator.Error!Constant {
8915 try self.ensureUnusedTypeCapacity(1, Type.Array, 0);
8916 try self.ensureUnusedConstantCapacity(1, NoExtra, 0);
8917 return self.stringNullConstAssumeCapacity(val);
8918}
8919
8920pub fn stringNullValue(self: *Builder, val: String) Allocator.Error!Value {
8921 return (try self.stringNullConst(val)).toValue();
8922}
8923
8924pub fn vectorConst(self: *Builder, ty: Type, vals: []const Constant) Allocator.Error!Constant {8943pub fn vectorConst(self: *Builder, ty: Type, vals: []const Constant) Allocator.Error!Constant {
8925 try self.ensureUnusedConstantCapacity(1, Constant.Aggregate, vals.len);8944 try self.ensureUnusedConstantCapacity(1, Constant.Aggregate, vals.len);
8926 return self.vectorConstAssumeCapacity(ty, vals);8945 return self.vectorConstAssumeCapacity(ty, vals);
...@@ -9354,7 +9373,7 @@ pub fn printUnbuffered(...@@ -9354,7 +9373,7 @@ pub fn printUnbuffered(
9354 defer metadata_formatter.need_comma = undefined;9373 defer metadata_formatter.need_comma = undefined;
9355 try writer.print("{ }{}", .{9374 try writer.print("{ }{}", .{
9356 function.alignment,9375 function.alignment,
9357 try metadata_formatter.fmt("!dbg ", global.dbg),9376 try metadata_formatter.fmt(" !dbg ", global.dbg),
9358 });9377 });
9359 }9378 }
9360 if (function.instructions.len > 0) {9379 if (function.instructions.len > 0) {
...@@ -9513,7 +9532,8 @@ pub fn printUnbuffered(...@@ -9513,7 +9532,8 @@ pub fn printUnbuffered(
9513 const name = instruction_index.name(&function);9532 const name = instruction_index.name(&function);
9514 if (@intFromEnum(instruction_index) > params_len)9533 if (@intFromEnum(instruction_index) > params_len)
9515 try writer.writeByte('\n');9534 try writer.writeByte('\n');
9516 try writer.print("{}:", .{name.fmt(self)});9535 try writer.print("{}:\n", .{name.fmt(self)});
9536 continue;
9517 },9537 },
9518 .br => |tag| {9538 .br => |tag| {
9519 const target: Function.Block.Index = @enumFromInt(instruction.data);9539 const target: Function.Block.Index = @enumFromInt(instruction.data);
...@@ -9965,6 +9985,7 @@ pub fn printUnbuffered(...@@ -9965,6 +9985,7 @@ pub fn printUnbuffered(
9965 .composite_union_type,9985 .composite_union_type,
9966 .composite_enumeration_type,9986 .composite_enumeration_type,
9967 .composite_array_type,9987 .composite_array_type,
9988 .composite_vector_type,
9968 => |kind| {9989 => |kind| {
9969 const extra = self.metadataExtraData(Metadata.CompositeType, metadata_item.data);9990 const extra = self.metadataExtraData(Metadata.CompositeType, metadata_item.data);
9970 try metadata_formatter.specialized(.@"distinct !", .DICompositeType, .{9991 try metadata_formatter.specialized(.@"distinct !", .DICompositeType, .{
...@@ -10165,9 +10186,6 @@ pub fn printUnbuffered(...@@ -10165,9 +10186,6 @@ pub fn printUnbuffered(
10165 .expr = extra.expression,10186 .expr = extra.expression,
10166 }, writer);10187 }, writer);
10167 },10188 },
10168 else => {
10169 try writer.writeByte('\n');
10170 },
10171 }10189 }
10172 }10190 }
10173 }10191 }
...@@ -10206,7 +10224,7 @@ fn printEscapedString(...@@ -10206,7 +10224,7 @@ fn printEscapedString(
10206fn ensureUnusedGlobalCapacity(self: *Builder, name: String) Allocator.Error!void {10224fn ensureUnusedGlobalCapacity(self: *Builder, name: String) Allocator.Error!void {
10207 try self.string_map.ensureUnusedCapacity(self.gpa, 1);10225 try self.string_map.ensureUnusedCapacity(self.gpa, 1);
10208 if (name.slice(self)) |id| {10226 if (name.slice(self)) |id| {
10209 const count: usize = comptime std.fmt.count("{d}" ++ .{0}, .{std.math.maxInt(u32)});10227 const count: usize = comptime std.fmt.count("{d}", .{std.math.maxInt(u32)});
10210 try self.string_bytes.ensureUnusedCapacity(self.gpa, id.len + count);10228 try self.string_bytes.ensureUnusedCapacity(self.gpa, id.len + count);
10211 }10229 }
10212 try self.string_indices.ensureUnusedCapacity(self.gpa, 1);10230 try self.string_indices.ensureUnusedCapacity(self.gpa, 1);
...@@ -10881,16 +10899,6 @@ fn stringConstAssumeCapacity(self: *Builder, val: String) Constant {...@@ -10881,16 +10899,6 @@ fn stringConstAssumeCapacity(self: *Builder, val: String) Constant {
10881 return result.constant;10899 return result.constant;
10882}10900}
1088310901
10884fn stringNullConstAssumeCapacity(self: *Builder, val: String) Constant {
10885 const slice = val.slice(self).?;
10886 const ty = self.arrayTypeAssumeCapacity(slice.len + 1, .i8);
10887 if (std.mem.allEqual(u8, slice, 0)) return self.zeroInitConstAssumeCapacity(ty);
10888 const result = self.getOrPutConstantNoExtraAssumeCapacity(
10889 .{ .tag = .string_null, .data = @intFromEnum(val) },
10890 );
10891 return result.constant;
10892}
10893
10894fn vectorConstAssumeCapacity(self: *Builder, ty: Type, vals: []const Constant) Constant {10902fn vectorConstAssumeCapacity(self: *Builder, ty: Type, vals: []const Constant) Constant {
10895 assert(ty.isVector(self));10903 assert(ty.isVector(self));
10896 assert(ty.vectorLen(self) == vals.len);10904 assert(ty.vectorLen(self) == vals.len);
...@@ -11756,8 +11764,8 @@ pub fn metadataStringFmt(self: *Builder, comptime fmt_str: []const u8, fmt_args:...@@ -11756,8 +11764,8 @@ pub fn metadataStringFmt(self: *Builder, comptime fmt_str: []const u8, fmt_args:
1175611764
11757pub fn metadataStringFmtAssumeCapacity(self: *Builder, comptime fmt_str: []const u8, fmt_args: anytype) MetadataString {11765pub fn metadataStringFmtAssumeCapacity(self: *Builder, comptime fmt_str: []const u8, fmt_args: anytype) MetadataString {
11758 const start = self.metadata_string_bytes.items.len;11766 const start = self.metadata_string_bytes.items.len;
11759 self.metadata_string_bytes.writer(self.gpa).print(fmt_str, fmt_args) catch unreachable;11767 self.metadata_string_bytes.writer(undefined).print(fmt_str, fmt_args) catch unreachable;
11760 const bytes: []const u8 = self.metadata_string_bytes.items[start..self.metadata_string_bytes.items.len];11768 const bytes: []const u8 = self.metadata_string_bytes.items[start..];
1176111769
11762 const gop = self.metadata_string_map.getOrPutAssumeCapacityAdapted(bytes, String.Adapter{ .builder = self });11770 const gop = self.metadata_string_map.getOrPutAssumeCapacityAdapted(bytes, String.Adapter{ .builder = self });
11763 if (gop.found_existing) {11771 if (gop.found_existing) {
...@@ -12042,7 +12050,7 @@ pub fn debugEnumerator(...@@ -12042,7 +12050,7 @@ pub fn debugEnumerator(
12042 bit_width: u32,12050 bit_width: u32,
12043 value: std.math.big.int.Const,12051 value: std.math.big.int.Const,
12044) Allocator.Error!Metadata {12052) Allocator.Error!Metadata {
12045 std.debug.assert(!(unsigned and !value.positive));12053 assert(!(unsigned and !value.positive));
12046 try self.ensureUnusedMetadataCapacity(1, Metadata.Enumerator, 0);12054 try self.ensureUnusedMetadataCapacity(1, Metadata.Enumerator, 0);
12047 try self.metadata_limbs.ensureUnusedCapacity(self.gpa, value.limbs.len);12055 try self.metadata_limbs.ensureUnusedCapacity(self.gpa, value.limbs.len);
12048 return self.debugEnumeratorAssumeCapacity(name, unsigned, bit_width, value);12056 return self.debugEnumeratorAssumeCapacity(name, unsigned, bit_width, value);
...@@ -12147,7 +12155,7 @@ pub fn debugConstant(self: *Builder, value: Constant) Allocator.Error!Metadata {...@@ -12147,7 +12155,7 @@ pub fn debugConstant(self: *Builder, value: Constant) Allocator.Error!Metadata {
12147}12155}
1214812156
12149pub fn debugForwardReferenceSetType(self: *Builder, fwd_ref: Metadata, ty: Metadata) void {12157pub fn debugForwardReferenceSetType(self: *Builder, fwd_ref: Metadata, ty: Metadata) void {
12150 std.debug.assert(12158 assert(
12151 @intFromEnum(fwd_ref) >= Metadata.first_forward_reference and12159 @intFromEnum(fwd_ref) >= Metadata.first_forward_reference and
12152 @intFromEnum(fwd_ref) <= Metadata.first_local_metadata,12160 @intFromEnum(fwd_ref) <= Metadata.first_local_metadata,
12153 );12161 );
...@@ -12226,7 +12234,8 @@ fn metadataDistinctAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anyt...@@ -12226,7 +12234,8 @@ fn metadataDistinctAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anyt
12226}12234}
1222712235
12228fn debugNamedAssumeCapacity(self: *Builder, name: MetadataString, operands: []const Metadata) void {12236fn debugNamedAssumeCapacity(self: *Builder, name: MetadataString, operands: []const Metadata) void {
12229 std.debug.assert(name != .none);12237 assert(!self.strip);
12238 assert(name != .none);
12230 const extra_index: u32 = @intCast(self.metadata_extra.items.len);12239 const extra_index: u32 = @intCast(self.metadata_extra.items.len);
12231 self.metadata_extra.appendSliceAssumeCapacity(@ptrCast(operands));12240 self.metadata_extra.appendSliceAssumeCapacity(@ptrCast(operands));
1223212241
...@@ -12238,6 +12247,7 @@ fn debugNamedAssumeCapacity(self: *Builder, name: MetadataString, operands: []co...@@ -12238,6 +12247,7 @@ fn debugNamedAssumeCapacity(self: *Builder, name: MetadataString, operands: []co
12238}12247}
1223912248
12240pub fn debugNoneAssumeCapacity(self: *Builder) Metadata {12249pub fn debugNoneAssumeCapacity(self: *Builder) Metadata {
12250 assert(!self.strip);
12241 return self.metadataSimpleAssumeCapacity(.none, .{});12251 return self.metadataSimpleAssumeCapacity(.none, .{});
12242}12252}
1224312253
...@@ -12246,6 +12256,7 @@ fn debugFileAssumeCapacity(...@@ -12246,6 +12256,7 @@ fn debugFileAssumeCapacity(
12246 filename: MetadataString,12256 filename: MetadataString,
12247 directory: MetadataString,12257 directory: MetadataString,
12248) Metadata {12258) Metadata {
12259 assert(!self.strip);
12249 return self.metadataDistinctAssumeCapacity(.file, Metadata.File{12260 return self.metadataDistinctAssumeCapacity(.file, Metadata.File{
12250 .filename = filename,12261 .filename = filename,
12251 .directory = directory,12262 .directory = directory,
...@@ -12260,6 +12271,7 @@ pub fn debugCompileUnitAssumeCapacity(...@@ -12260,6 +12271,7 @@ pub fn debugCompileUnitAssumeCapacity(
12260 globals: Metadata,12271 globals: Metadata,
12261 options: Metadata.CompileUnit.Options,12272 options: Metadata.CompileUnit.Options,
12262) Metadata {12273) Metadata {
12274 assert(!self.strip);
12263 return self.metadataDistinctAssumeCapacity(12275 return self.metadataDistinctAssumeCapacity(
12264 if (options.optimized) .@"compile_unit optimized" else .compile_unit,12276 if (options.optimized) .@"compile_unit optimized" else .compile_unit,
12265 Metadata.CompileUnit{12277 Metadata.CompileUnit{
...@@ -12282,6 +12294,7 @@ fn debugSubprogramAssumeCapacity(...@@ -12282,6 +12294,7 @@ fn debugSubprogramAssumeCapacity(
12282 options: Metadata.Subprogram.Options,12294 options: Metadata.Subprogram.Options,
12283 compile_unit: Metadata,12295 compile_unit: Metadata,
12284) Metadata {12296) Metadata {
12297 assert(!self.strip);
12285 const tag: Metadata.Tag = @enumFromInt(@intFromEnum(Metadata.Tag.subprogram) +12298 const tag: Metadata.Tag = @enumFromInt(@intFromEnum(Metadata.Tag.subprogram) +
12286 @as(u3, @truncate(@as(u32, @bitCast(options.sp_flags)) >> 2)));12299 @as(u3, @truncate(@as(u32, @bitCast(options.sp_flags)) >> 2)));
12287 return self.metadataDistinctAssumeCapacity(tag, Metadata.Subprogram{12300 return self.metadataDistinctAssumeCapacity(tag, Metadata.Subprogram{
...@@ -12297,6 +12310,7 @@ fn debugSubprogramAssumeCapacity(...@@ -12297,6 +12310,7 @@ fn debugSubprogramAssumeCapacity(
12297}12310}
1229812311
12299fn debugLexicalBlockAssumeCapacity(self: *Builder, scope: Metadata, file: Metadata, line: u32, column: u32) Metadata {12312fn debugLexicalBlockAssumeCapacity(self: *Builder, scope: Metadata, file: Metadata, line: u32, column: u32) Metadata {
12313 assert(!self.strip);
12300 return self.metadataDistinctAssumeCapacity(.lexical_block, Metadata.LexicalBlock{12314 return self.metadataDistinctAssumeCapacity(.lexical_block, Metadata.LexicalBlock{
12301 .scope = scope,12315 .scope = scope,
12302 .file = file,12316 .file = file,
...@@ -12306,6 +12320,7 @@ fn debugLexicalBlockAssumeCapacity(self: *Builder, scope: Metadata, file: Metada...@@ -12306,6 +12320,7 @@ fn debugLexicalBlockAssumeCapacity(self: *Builder, scope: Metadata, file: Metada
12306}12320}
1230712321
12308fn debugLocationAssumeCapacity(self: *Builder, line: u32, column: u32, scope: Metadata, inlined_at: Metadata) Metadata {12322fn debugLocationAssumeCapacity(self: *Builder, line: u32, column: u32, scope: Metadata, inlined_at: Metadata) Metadata {
12323 assert(!self.strip);
12309 return self.metadataSimpleAssumeCapacity(.location, Metadata.Location{12324 return self.metadataSimpleAssumeCapacity(.location, Metadata.Location{
12310 .line = line,12325 .line = line,
12311 .column = column,12326 .column = column,
...@@ -12315,6 +12330,7 @@ fn debugLocationAssumeCapacity(self: *Builder, line: u32, column: u32, scope: Me...@@ -12315,6 +12330,7 @@ fn debugLocationAssumeCapacity(self: *Builder, line: u32, column: u32, scope: Me
12315}12330}
1231612331
12317fn debugBoolTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bits: u64) Metadata {12332fn debugBoolTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bits: u64) Metadata {
12333 assert(!self.strip);
12318 return self.metadataDistinctAssumeCapacity(.basic_bool_type, Metadata.BasicType{12334 return self.metadataDistinctAssumeCapacity(.basic_bool_type, Metadata.BasicType{
12319 .name = name,12335 .name = name,
12320 .size_in_bits_lo = @truncate(size_in_bits),12336 .size_in_bits_lo = @truncate(size_in_bits),
...@@ -12323,6 +12339,7 @@ fn debugBoolTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bit...@@ -12323,6 +12339,7 @@ fn debugBoolTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bit
12323}12339}
1232412340
12325fn debugUnsignedTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bits: u64) Metadata {12341fn debugUnsignedTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bits: u64) Metadata {
12342 assert(!self.strip);
12326 return self.metadataDistinctAssumeCapacity(.basic_unsigned_type, Metadata.BasicType{12343 return self.metadataDistinctAssumeCapacity(.basic_unsigned_type, Metadata.BasicType{
12327 .name = name,12344 .name = name,
12328 .size_in_bits_lo = @truncate(size_in_bits),12345 .size_in_bits_lo = @truncate(size_in_bits),
...@@ -12331,6 +12348,7 @@ fn debugUnsignedTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in...@@ -12331,6 +12348,7 @@ fn debugUnsignedTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in
12331}12348}
1233212349
12333fn debugSignedTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bits: u64) Metadata {12350fn debugSignedTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bits: u64) Metadata {
12351 assert(!self.strip);
12334 return self.metadataDistinctAssumeCapacity(.basic_signed_type, Metadata.BasicType{12352 return self.metadataDistinctAssumeCapacity(.basic_signed_type, Metadata.BasicType{
12335 .name = name,12353 .name = name,
12336 .size_in_bits_lo = @truncate(size_in_bits),12354 .size_in_bits_lo = @truncate(size_in_bits),
...@@ -12339,6 +12357,7 @@ fn debugSignedTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_b...@@ -12339,6 +12357,7 @@ fn debugSignedTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_b
12339}12357}
1234012358
12341fn debugFloatTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bits: u64) Metadata {12359fn debugFloatTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bits: u64) Metadata {
12360 assert(!self.strip);
12342 return self.metadataDistinctAssumeCapacity(.basic_float_type, Metadata.BasicType{12361 return self.metadataDistinctAssumeCapacity(.basic_float_type, Metadata.BasicType{
12343 .name = name,12362 .name = name,
12344 .size_in_bits_lo = @truncate(size_in_bits),12363 .size_in_bits_lo = @truncate(size_in_bits),
...@@ -12347,6 +12366,7 @@ fn debugFloatTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bi...@@ -12347,6 +12366,7 @@ fn debugFloatTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bi
12347}12366}
1234812367
12349fn debugForwardReferenceAssumeCapacity(self: *Builder) Metadata {12368fn debugForwardReferenceAssumeCapacity(self: *Builder) Metadata {
12369 assert(!self.strip);
12350 const index = Metadata.first_forward_reference + self.metadata_forward_references.items.len;12370 const index = Metadata.first_forward_reference + self.metadata_forward_references.items.len;
12351 self.metadata_forward_references.appendAssumeCapacity(.none);12371 self.metadata_forward_references.appendAssumeCapacity(.none);
12352 return @enumFromInt(index);12372 return @enumFromInt(index);
...@@ -12363,6 +12383,7 @@ fn debugStructTypeAssumeCapacity(...@@ -12363,6 +12383,7 @@ fn debugStructTypeAssumeCapacity(
12363 align_in_bits: u64,12383 align_in_bits: u64,
12364 fields_tuple: Metadata,12384 fields_tuple: Metadata,
12365) Metadata {12385) Metadata {
12386 assert(!self.strip);
12366 return self.debugCompositeTypeAssumeCapacity(12387 return self.debugCompositeTypeAssumeCapacity(
12367 .composite_struct_type,12388 .composite_struct_type,
12368 name,12389 name,
...@@ -12387,6 +12408,7 @@ fn debugUnionTypeAssumeCapacity(...@@ -12387,6 +12408,7 @@ fn debugUnionTypeAssumeCapacity(
12387 align_in_bits: u64,12408 align_in_bits: u64,
12388 fields_tuple: Metadata,12409 fields_tuple: Metadata,
12389) Metadata {12410) Metadata {
12411 assert(!self.strip);
12390 return self.debugCompositeTypeAssumeCapacity(12412 return self.debugCompositeTypeAssumeCapacity(
12391 .composite_union_type,12413 .composite_union_type,
12392 name,12414 name,
...@@ -12411,6 +12433,7 @@ fn debugEnumerationTypeAssumeCapacity(...@@ -12411,6 +12433,7 @@ fn debugEnumerationTypeAssumeCapacity(
12411 align_in_bits: u64,12433 align_in_bits: u64,
12412 fields_tuple: Metadata,12434 fields_tuple: Metadata,
12413) Metadata {12435) Metadata {
12436 assert(!self.strip);
12414 return self.debugCompositeTypeAssumeCapacity(12437 return self.debugCompositeTypeAssumeCapacity(
12415 .composite_enumeration_type,12438 .composite_enumeration_type,
12416 name,12439 name,
...@@ -12435,6 +12458,7 @@ fn debugArrayTypeAssumeCapacity(...@@ -12435,6 +12458,7 @@ fn debugArrayTypeAssumeCapacity(
12435 align_in_bits: u64,12458 align_in_bits: u64,
12436 fields_tuple: Metadata,12459 fields_tuple: Metadata,
12437) Metadata {12460) Metadata {
12461 assert(!self.strip);
12438 return self.debugCompositeTypeAssumeCapacity(12462 return self.debugCompositeTypeAssumeCapacity(
12439 .composite_array_type,12463 .composite_array_type,
12440 name,12464 name,
...@@ -12459,6 +12483,7 @@ fn debugVectorTypeAssumeCapacity(...@@ -12459,6 +12483,7 @@ fn debugVectorTypeAssumeCapacity(
12459 align_in_bits: u64,12483 align_in_bits: u64,
12460 fields_tuple: Metadata,12484 fields_tuple: Metadata,
12461) Metadata {12485) Metadata {
12486 assert(!self.strip);
12462 return self.debugCompositeTypeAssumeCapacity(12487 return self.debugCompositeTypeAssumeCapacity(
12463 .composite_vector_type,12488 .composite_vector_type,
12464 name,12489 name,
...@@ -12484,6 +12509,7 @@ fn debugCompositeTypeAssumeCapacity(...@@ -12484,6 +12509,7 @@ fn debugCompositeTypeAssumeCapacity(
12484 align_in_bits: u64,12509 align_in_bits: u64,
12485 fields_tuple: Metadata,12510 fields_tuple: Metadata,
12486) Metadata {12511) Metadata {
12512 assert(!self.strip);
12487 return self.metadataDistinctAssumeCapacity(tag, Metadata.CompositeType{12513 return self.metadataDistinctAssumeCapacity(tag, Metadata.CompositeType{
12488 .name = name,12514 .name = name,
12489 .file = file,12515 .file = file,
...@@ -12509,6 +12535,7 @@ fn debugPointerTypeAssumeCapacity(...@@ -12509,6 +12535,7 @@ fn debugPointerTypeAssumeCapacity(
12509 align_in_bits: u64,12535 align_in_bits: u64,
12510 offset_in_bits: u64,12536 offset_in_bits: u64,
12511) Metadata {12537) Metadata {
12538 assert(!self.strip);
12512 return self.metadataDistinctAssumeCapacity(.derived_pointer_type, Metadata.DerivedType{12539 return self.metadataDistinctAssumeCapacity(.derived_pointer_type, Metadata.DerivedType{
12513 .name = name,12540 .name = name,
12514 .file = file,12541 .file = file,
...@@ -12535,6 +12562,7 @@ fn debugMemberTypeAssumeCapacity(...@@ -12535,6 +12562,7 @@ fn debugMemberTypeAssumeCapacity(
12535 align_in_bits: u64,12562 align_in_bits: u64,
12536 offset_in_bits: u64,12563 offset_in_bits: u64,
12537) Metadata {12564) Metadata {
12565 assert(!self.strip);
12538 return self.metadataDistinctAssumeCapacity(.derived_member_type, Metadata.DerivedType{12566 return self.metadataDistinctAssumeCapacity(.derived_member_type, Metadata.DerivedType{
12539 .name = name,12567 .name = name,
12540 .file = file,12568 .file = file,
...@@ -12554,6 +12582,7 @@ fn debugSubroutineTypeAssumeCapacity(...@@ -12554,6 +12582,7 @@ fn debugSubroutineTypeAssumeCapacity(
12554 self: *Builder,12582 self: *Builder,
12555 types_tuple: Metadata,12583 types_tuple: Metadata,
12556) Metadata {12584) Metadata {
12585 assert(!self.strip);
12557 return self.metadataDistinctAssumeCapacity(.subroutine_type, Metadata.SubroutineType{12586 return self.metadataDistinctAssumeCapacity(.subroutine_type, Metadata.SubroutineType{
12558 .types_tuple = types_tuple,12587 .types_tuple = types_tuple,
12559 });12588 });
...@@ -12566,6 +12595,7 @@ fn debugEnumeratorAssumeCapacity(...@@ -12566,6 +12595,7 @@ fn debugEnumeratorAssumeCapacity(
12566 bit_width: u32,12595 bit_width: u32,
12567 value: std.math.big.int.Const,12596 value: std.math.big.int.Const,
12568) Metadata {12597) Metadata {
12598 assert(!self.strip);
12569 const Key = struct { tag: Metadata.Tag, index: Metadata };12599 const Key = struct { tag: Metadata.Tag, index: Metadata };
12570 const Adapter = struct {12600 const Adapter = struct {
12571 pub fn hash(_: @This(), key: Key) u32 {12601 pub fn hash(_: @This(), key: Key) u32 {
...@@ -12587,7 +12617,7 @@ fn debugEnumeratorAssumeCapacity(...@@ -12587,7 +12617,7 @@ fn debugEnumeratorAssumeCapacity(
12587 else12617 else
12588 .enumerator_signed_negative;12618 .enumerator_signed_negative;
1258912619
12590 std.debug.assert(!(tag == .enumerator_unsigned and !value.positive));12620 assert(!(tag == .enumerator_unsigned and !value.positive));
1259112621
12592 const gop = self.metadata_map.getOrPutAssumeCapacityAdapted(12622 const gop = self.metadata_map.getOrPutAssumeCapacityAdapted(
12593 Key{ .tag = tag, .index = @enumFromInt(self.metadata_map.count()) },12623 Key{ .tag = tag, .index = @enumFromInt(self.metadata_map.count()) },
...@@ -12616,6 +12646,7 @@ fn debugSubrangeAssumeCapacity(...@@ -12616,6 +12646,7 @@ fn debugSubrangeAssumeCapacity(
12616 lower_bound: Metadata,12646 lower_bound: Metadata,
12617 count: Metadata,12647 count: Metadata,
12618) Metadata {12648) Metadata {
12649 assert(!self.strip);
12619 return self.metadataDistinctAssumeCapacity(.subrange, Metadata.Subrange{12650 return self.metadataDistinctAssumeCapacity(.subrange, Metadata.Subrange{
12620 .lower_bound = lower_bound,12651 .lower_bound = lower_bound,
12621 .count = count,12652 .count = count,
...@@ -12626,6 +12657,7 @@ fn debugExpressionAssumeCapacity(...@@ -12626,6 +12657,7 @@ fn debugExpressionAssumeCapacity(
12626 self: *Builder,12657 self: *Builder,
12627 elements: []const u32,12658 elements: []const u32,
12628) Metadata {12659) Metadata {
12660 assert(!self.strip);
12629 const Key = struct {12661 const Key = struct {
12630 elements: []const u32,12662 elements: []const u32,
12631 };12663 };
...@@ -12672,6 +12704,7 @@ fn debugTupleAssumeCapacity(...@@ -12672,6 +12704,7 @@ fn debugTupleAssumeCapacity(
12672 self: *Builder,12704 self: *Builder,
12673 elements: []const Metadata,12705 elements: []const Metadata,
12674) Metadata {12706) Metadata {
12707 assert(!self.strip);
12675 const Key = struct {12708 const Key = struct {
12676 elements: []const Metadata,12709 elements: []const Metadata,
12677 };12710 };
...@@ -12720,6 +12753,7 @@ fn debugModuleFlagAssumeCapacity(...@@ -12720,6 +12753,7 @@ fn debugModuleFlagAssumeCapacity(
12720 name: MetadataString,12753 name: MetadataString,
12721 constant: Metadata,12754 constant: Metadata,
12722) Metadata {12755) Metadata {
12756 assert(!self.strip);
12723 return self.metadataSimpleAssumeCapacity(.module_flag, Metadata.ModuleFlag{12757 return self.metadataSimpleAssumeCapacity(.module_flag, Metadata.ModuleFlag{
12724 .behavior = behavior,12758 .behavior = behavior,
12725 .name = name,12759 .name = name,
...@@ -12734,7 +12768,8 @@ fn debugLocalVarAssumeCapacity(...@@ -12734,7 +12768,8 @@ fn debugLocalVarAssumeCapacity(
12734 scope: Metadata,12768 scope: Metadata,
12735 line: u32,12769 line: u32,
12736 ty: Metadata,12770 ty: Metadata,
12737) Allocator.Error!Metadata {12771) Metadata {
12772 assert(!self.strip);
12738 return self.metadataDistinctAssumeCapacity(.local_var, Metadata.LocalVar{12773 return self.metadataDistinctAssumeCapacity(.local_var, Metadata.LocalVar{
12739 .name = name,12774 .name = name,
12740 .file = file,12775 .file = file,
...@@ -12752,7 +12787,8 @@ fn debugParameterAssumeCapacity(...@@ -12752,7 +12787,8 @@ fn debugParameterAssumeCapacity(
12752 line: u32,12787 line: u32,
12753 ty: Metadata,12788 ty: Metadata,
12754 arg_no: u32,12789 arg_no: u32,
12755) Allocator.Error!Metadata {12790) Metadata {
12791 assert(!self.strip);
12756 return self.metadataDistinctAssumeCapacity(.parameter, Metadata.Parameter{12792 return self.metadataDistinctAssumeCapacity(.parameter, Metadata.Parameter{
12757 .name = name,12793 .name = name,
12758 .file = file,12794 .file = file,
...@@ -12773,7 +12809,8 @@ fn debugGlobalVarAssumeCapacity(...@@ -12773,7 +12809,8 @@ fn debugGlobalVarAssumeCapacity(
12773 ty: Metadata,12809 ty: Metadata,
12774 variable: Variable.Index,12810 variable: Variable.Index,
12775 options: Metadata.GlobalVar.Options,12811 options: Metadata.GlobalVar.Options,
12776) Allocator.Error!Metadata {12812) Metadata {
12813 assert(!self.strip);
12777 return self.metadataDistinctAssumeCapacity(12814 return self.metadataDistinctAssumeCapacity(
12778 if (options.local) .@"global_var local" else .global_var,12815 if (options.local) .@"global_var local" else .global_var,
12779 Metadata.GlobalVar{12816 Metadata.GlobalVar{
...@@ -12793,6 +12830,7 @@ fn debugGlobalVarExpressionAssumeCapacity(...@@ -12793,6 +12830,7 @@ fn debugGlobalVarExpressionAssumeCapacity(
12793 variable: Metadata,12830 variable: Metadata,
12794 expression: Metadata,12831 expression: Metadata,
12795) Metadata {12832) Metadata {
12833 assert(!self.strip);
12796 return self.metadataDistinctAssumeCapacity(.global_var_expression, Metadata.GlobalVarExpression{12834 return self.metadataDistinctAssumeCapacity(.global_var_expression, Metadata.GlobalVarExpression{
12797 .variable = variable,12835 .variable = variable,
12798 .expression = expression,12836 .expression = expression,
...@@ -12800,6 +12838,7 @@ fn debugGlobalVarExpressionAssumeCapacity(...@@ -12800,6 +12838,7 @@ fn debugGlobalVarExpressionAssumeCapacity(
12800}12838}
1280112839
12802fn debugConstantAssumeCapacity(self: *Builder, constant: Constant) Metadata {12840fn debugConstantAssumeCapacity(self: *Builder, constant: Constant) Metadata {
12841 assert(!self.strip);
12803 const Adapter = struct {12842 const Adapter = struct {
12804 builder: *const Builder,12843 builder: *const Builder,
12805 pub fn hash(_: @This(), key: Constant) u32 {12844 pub fn hash(_: @This(), key: Constant) u32 {
...@@ -13528,18 +13567,16 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -13528,18 +13567,16 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
13528 }13567 }
13529 },13568 },
13530 .string,13569 .string,
13531 .string_null,
13532 => {13570 => {
13533 const str: String = @enumFromInt(data);13571 const str: String = @enumFromInt(data);
13534 if (str == .none) {13572 if (str == .none) {
13535 try constants_block.writeAbbrev(Constants.Null{});13573 try constants_block.writeAbbrev(Constants.Null{});
13536 } else {13574 } else {
13537 const slice = str.slice(self) orelse unreachable;13575 const slice = str.slice(self) orelse unreachable;
13538 switch (tags[index]) {13576 if (slice.len > 0 and slice[slice.len - 1] == 0)
13539 .string => try constants_block.writeAbbrev(Constants.String{ .string = slice }),13577 try constants_block.writeAbbrev(Constants.CString{ .string = slice[0 .. slice.len - 1] })
13540 .string_null => try constants_block.writeAbbrev(Constants.CString{ .string = slice }),13578 else
13541 else => unreachable,13579 try constants_block.writeAbbrev(Constants.String{ .string = slice });
13542 }
13543 }13580 }
13544 },13581 },
13545 .bitcast,13582 .bitcast,
...@@ -13918,7 +13955,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -13918,7 +13955,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
13918 },13955 },
13919 .location => {13956 .location => {
13920 const extra = self.metadataExtraData(Metadata.Location, data);13957 const extra = self.metadataExtraData(Metadata.Location, data);
13921 std.debug.assert(extra.scope != .none);13958 assert(extra.scope != .none);
13922 try metadata_block.writeAbbrev(MetadataBlock.Location{13959 try metadata_block.writeAbbrev(MetadataBlock.Location{
13923 .line = extra.line,13960 .line = extra.line,
13924 .column = extra.column,13961 .column = extra.column,