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 {
464464 return comptime blk: {
465465 const fieldInfos = fields(T);
466466 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 ++ "";
468469 break :blk &names;
469470 };
470471}
src/codegen/llvm.zig+81-78
......@@ -849,51 +849,53 @@ pub const Object = struct {
849849
850850 builder.data_layout = try builder.fmt("{}", .{DataLayoutBuilder{ .target = target }});
851851
852 // We fully resolve all paths at this point to avoid lack of
853 // source line info in stack traces or lack of debugging
854 // information which, if relative paths were used, would be
855 // very location dependent.
856 // TODO: the only concern I have with this is WASI as either host or target, should
857 // we leave the paths as relative then?
858 // TODO: This is totally wrong. In dwarf, paths are encoded as relative to
859 // a particular directory, and then the directory path is specified elsewhere.
860 // In the compiler frontend we have it stored correctly in this
861 // way already, but here we throw all that sweet information
862 // into the garbage can by converting into absolute paths. What
863 // a terrible tragedy.
864 const compile_unit_dir = blk: {
865 if (comp.module) |zcu| m: {
866 const d = try zcu.root_mod.root.joinString(arena, "");
867 if (d.len == 0) break :m;
868 if (std.fs.path.isAbsolute(d)) break :blk d;
869 break :blk std.fs.realpathAlloc(arena, d) catch break :blk d;
870 }
871 break :blk try std.process.getCwdAlloc(arena);
872 };
852 const debug_compile_unit, const debug_enums_fwd_ref, const debug_globals_fwd_ref =
853 if (!builder.strip)
854 debug_info: {
855 // We fully resolve all paths at this point to avoid lack of
856 // source line info in stack traces or lack of debugging
857 // information which, if relative paths were used, would be
858 // very location dependent.
859 // TODO: the only concern I have with this is WASI as either host or target, should
860 // we leave the paths as relative then?
861 // TODO: This is totally wrong. In dwarf, paths are encoded as relative to
862 // a particular directory, and then the directory path is specified elsewhere.
863 // In the compiler frontend we have it stored correctly in this
864 // way already, but here we throw all that sweet information
865 // into the garbage can by converting into absolute paths. What
866 // a terrible tragedy.
867 const compile_unit_dir = blk: {
868 if (comp.module) |zcu| m: {
869 const d = try zcu.root_mod.root.joinString(arena, "");
870 if (d.len == 0) break :m;
871 if (std.fs.path.isAbsolute(d)) break :blk d;
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(
875 try builder.metadataString(comp.root_name),
876 try builder.metadataString(compile_unit_dir),
877 );
877 const debug_file = try builder.debugFile(
878 try builder.metadataString(comp.root_name),
879 try builder.metadataString(compile_unit_dir),
880 );
878881
879 const debug_enums_fwd_ref = try builder.debugForwardReference();
880 const debug_globals_fwd_ref = try builder.debugForwardReference();
881
882 const debug_compile_unit = try builder.debugCompileUnit(
883 debug_file,
884 // Don't use the version string here; LLVM misparses it when it
885 // includes the git revision.
886 try builder.metadataStringFmt("zig {d}.{d}.{d}", .{
887 build_options.semver.major,
888 build_options.semver.minor,
889 build_options.semver.patch,
890 }),
891 debug_enums_fwd_ref,
892 debug_globals_fwd_ref,
893 .{ .optimized = comp.root_mod.optimize_mode != .Debug },
894 );
882 const debug_enums_fwd_ref = try builder.debugForwardReference();
883 const debug_globals_fwd_ref = try builder.debugForwardReference();
884
885 const debug_compile_unit = try builder.debugCompileUnit(
886 debug_file,
887 // Don't use the version string here; LLVM misparses it when it
888 // includes the git revision.
889 try builder.metadataStringFmt("zig {d}.{d}.{d}", .{
890 build_options.semver.major,
891 build_options.semver.minor,
892 build_options.semver.patch,
893 }),
894 debug_enums_fwd_ref,
895 debug_globals_fwd_ref,
896 .{ .optimized = comp.root_mod.optimize_mode != .Debug },
897 );
895898
896 if (!builder.strip) {
897899 const debug_info_version = try builder.debugModuleFlag(
898900 try builder.debugConstant(try builder.intConst(.i32, 2)),
899901 try builder.metadataString("Debug Info Version"),
......@@ -901,6 +903,7 @@ pub const Object = struct {
901903 );
902904
903905 switch (comp.config.debug_format) {
906 .strip => unreachable,
904907 .dwarf => |f| {
905908 const dwarf_version = try builder.debugModuleFlag(
906909 try builder.debugConstant(try builder.intConst(.i32, 2)),
......@@ -939,11 +942,11 @@ pub const Object = struct {
939942 code_view,
940943 });
941944 },
942 .strip => unreachable,
943945 }
944946
945947 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
948951 const obj = try arena.create(Object);
949952 obj.* = .{
......@@ -1004,8 +1007,8 @@ pub const Object = struct {
10041007
10051008 llvm_errors[0] = try o.builder.undefConst(llvm_slice_ty);
10061009 for (llvm_errors[1..], error_name_list[1..]) |*llvm_error, name| {
1007 const name_string = try o.builder.string(mod.intern_pool.stringToSlice(name));
1008 const name_init = try o.builder.stringNullConst(name_string);
1010 const name_string = try o.builder.stringNull(mod.intern_pool.stringToSlice(name));
1011 const name_init = try o.builder.stringConst(name_string);
10091012 const name_variable_index =
10101013 try o.builder.addVariable(.empty, name_init.typeOf(&o.builder), .default);
10111014 try name_variable_index.setInitializer(name_init, &o.builder);
......@@ -1016,7 +1019,7 @@ pub const Object = struct {
10161019
10171020 llvm_error.* = try o.builder.structConst(llvm_slice_ty, &.{
10181021 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),
10201023 });
10211024 }
10221025
......@@ -1145,28 +1148,27 @@ pub const Object = struct {
11451148 try self.genCmpLtErrorsLenFunction();
11461149 try self.genModuleLevelAssembly();
11471150
1148 {
1149 var i: usize = 0;
1150 while (i < self.debug_unresolved_namespace_scopes.count()) : (i += 1) {
1151 const namespace_index = self.debug_unresolved_namespace_scopes.keys()[i];
1152 const fwd_ref = self.debug_unresolved_namespace_scopes.values()[i];
1151 if (!self.builder.strip) {
1152 for (
1153 self.debug_unresolved_namespace_scopes.keys(),
1154 self.debug_unresolved_namespace_scopes.values(),
1155 ) |namespace_index, fwd_ref| {
11531156 const namespace = self.module.namespacePtr(namespace_index);
1154
11551157 const debug_type = try self.lowerDebugType(namespace.ty);
11561158
11571159 self.builder.debugForwardReferenceSetType(fwd_ref, debug_type);
11581160 }
1159 }
11601161
1161 self.builder.debugForwardReferenceSetType(
1162 self.debug_enums_fwd_ref,
1163 try self.builder.debugTuple(self.debug_enums.items),
1164 );
1162 self.builder.debugForwardReferenceSetType(
1163 self.debug_enums_fwd_ref,
1164 try self.builder.debugTuple(self.debug_enums.items),
1165 );
11651166
1166 self.builder.debugForwardReferenceSetType(
1167 self.debug_globals_fwd_ref,
1168 try self.builder.debugTuple(self.debug_globals.items),
1169 );
1167 self.builder.debugForwardReferenceSetType(
1168 self.debug_globals_fwd_ref,
1169 try self.builder.debugTuple(self.debug_globals.items),
1170 );
1171 }
11701172
11711173 if (options.pre_ir_path) |path| {
11721174 if (std.mem.eql(u8, path, "-")) {
......@@ -1241,13 +1243,12 @@ pub const Object = struct {
12411243 };
12421244 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);
12451249 var target: *llvm.Target = undefined;
1246 if (llvm.Target.getFromTriple(
1247 self.builder.target_triple.slice(&self.builder).?,
1248 &target,
1249 &error_message,
1250 ).toBool()) {
1250 var error_message: [*:0]const u8 = undefined;
1251 if (llvm.Target.getFromTriple(target_triple_sentinel, &target, &error_message).toBool()) {
12511252 defer llvm.disposeMessage(error_message);
12521253
12531254 log.err("LLVM failed to parse '{s}': {s}", .{
......@@ -1286,7 +1287,7 @@ pub const Object = struct {
12861287
12871288 var target_machine = llvm.TargetMachine.create(
12881289 target,
1289 self.builder.target_triple.slice(&self.builder).?,
1290 target_triple_sentinel,
12901291 if (self.module.comp.root_mod.resolved_target.result.cpu.model.llvm_name) |s| s.ptr else null,
12911292 self.module.comp.root_mod.resolved_target.llvm_cpu_features.?,
12921293 opt_level,
......@@ -1640,15 +1641,15 @@ pub const Object = struct {
16401641
16411642 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: {
16461647 const line_number = decl.src_line + 1;
16471648 const is_internal_linkage = decl.val.getExternFunc(zcu) == null and
16481649 !zcu.decl_exports.contains(decl_index);
16491650 const debug_decl_type = try o.lowerDebugType(decl.ty);
16501651
1651 break :blk try o.builder.debugSubprogram(
1652 const subprogram = try o.builder.debugSubprogram(
16521653 file,
16531654 try o.builder.metadataString(ip.stringToSlice(decl.name)),
16541655 try o.builder.metadataStringFromString(function_index.name(&o.builder)),
......@@ -1668,8 +1669,9 @@ pub const Object = struct {
16681669 },
16691670 o.debug_compile_unit,
16701671 );
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
16741676 var fg: FuncGen = .{
16751677 .gpa = gpa,
......@@ -1924,7 +1926,8 @@ pub const Object = struct {
19241926 o: *Object,
19251927 ty: Type,
19261928 ) Allocator.Error!Builder.Metadata {
1927 if (o.builder.strip) return .none;
1929 assert(!o.builder.strip);
1930
19281931 const gpa = o.gpa;
19291932 const target = o.target;
19301933 const mod = o.module;
......@@ -4608,8 +4611,8 @@ pub const Object = struct {
46084611 defer wip_switch.finish(&wip);
46094612
46104613 for (0..enum_type.names.len) |field_index| {
4611 const name = try o.builder.string(ip.stringToSlice(enum_type.names.get(ip)[field_index]));
4612 const name_init = try o.builder.stringNullConst(name);
4614 const name = try o.builder.stringNull(ip.stringToSlice(enum_type.names.get(ip)[field_index]));
4615 const name_init = try o.builder.stringConst(name);
46134616 const name_variable_index =
46144617 try o.builder.addVariable(.empty, name_init.typeOf(&o.builder), .default);
46154618 try name_variable_index.setInitializer(name_init, &o.builder);
......@@ -4620,7 +4623,7 @@ pub const Object = struct {
46204623
46214624 const name_val = try o.builder.structValue(ret_ty, &.{
46224625 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),
46244627 });
46254628
46264629 const return_block = try wip.block(1, "Name");
src/codegen/llvm/Builder.zig+146-109
......@@ -77,11 +77,11 @@ pub const String = enum(u32) {
7777 return self.toIndex() == null;
7878 }
7979
80 pub fn slice(self: String, builder: *const Builder) ?[:0]const u8 {
80 pub fn slice(self: String, builder: *const Builder) ?[]const u8 {
8181 const index = self.toIndex() orelse return null;
8282 const start = builder.string_indices.items[index];
8383 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];
8585 }
8686
8787 const FormatData = struct {
......@@ -94,17 +94,21 @@ pub const String = enum(u32) {
9494 _: std.fmt.FormatOptions,
9595 writer: anytype,
9696 ) @TypeOf(writer).Error!void {
97 if (comptime std.mem.indexOfNone(u8, fmt_str, "@\"")) |_|
97 if (comptime std.mem.indexOfNone(u8, fmt_str, "\"r")) |_|
9898 @compileError("invalid format string: '" ++ fmt_str ++ "'");
9999 assert(data.string != .none);
100 const sentinel_slice = data.string.slice(data.builder) orelse
100 const string_slice = data.string.slice(data.builder) orelse
101101 return writer.print("{d}", .{@intFromEnum(data.string)});
102 try printEscapedString(sentinel_slice[0 .. sentinel_slice.len + comptime @intFromBool(
103 std.mem.indexOfScalar(u8, fmt_str, '@') != null,
104 )], if (comptime std.mem.indexOfScalar(u8, fmt_str, '"')) |_|
105 .always_quote
106 else
107 .quote_unless_valid_identifier, writer);
102 if (comptime std.mem.indexOfScalar(u8, fmt_str, 'r')) |_|
103 return writer.writeAll(string_slice);
104 try printEscapedString(
105 string_slice,
106 if (comptime std.mem.indexOfScalar(u8, fmt_str, '"')) |_|
107 .always_quote
108 else
109 .quote_unless_valid_identifier,
110 writer,
111 );
108112 }
109113 pub fn fmt(self: String, builder: *const Builder) std.fmt.Formatter(format) {
110114 return .{ .data = .{ .string = self, .builder = builder } };
......@@ -4597,13 +4601,6 @@ pub const Function = struct {
45974601 ) std.fmt.Formatter(format) {
45984602 return .{ .data = .{ .instruction = self, .function = function, .builder = builder } };
45994603 }
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 }
46074604 };
46084605
46094606 pub const ExtraIndex = u32;
......@@ -5931,15 +5928,47 @@ pub const WipFunction = struct {
59315928
59325929 var wip_name: struct {
59335930 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 {
5936 if (old_name != .empty) return old_name;
5934 fn map(wip_name: *@This(), name: String, sep: []const u8) Allocator.Error!String {
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;
5939 wip_name.next_name = @enumFromInt(@intFromEnum(new_name) + 1);
5940 return new_name;
5950 while (true) {
5951 gop.value_ptr.* = @enumFromInt(@intFromEnum(gop.value_ptr.*) + 1);
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 }
59415965 }
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
59435972 var value_index: u32 = 0;
59445973 for (0..params_len) |param_index| {
59455974 const old_argument_index: Instruction.Index = @enumFromInt(param_index);
......@@ -5950,8 +5979,9 @@ pub const WipFunction = struct {
59505979 value_indices[function.instructions.len] = value_index;
59515980 value_index += 1;
59525981 function.instructions.appendAssumeCapacity(argument);
5953 names[@intFromEnum(new_argument_index)] = wip_name.map(
5982 names[@intFromEnum(new_argument_index)] = try wip_name.map(
59545983 if (self.builder.strip) .empty else self.names.items[@intFromEnum(old_argument_index)],
5984 ".",
59555985 );
59565986 if (self.debug_locations.get(old_argument_index)) |location| {
59575987 debug_locations.putAssumeCapacity(new_argument_index, location);
......@@ -5967,7 +5997,7 @@ pub const WipFunction = struct {
59675997 .tag = .block,
59685998 .data = current_block.incoming,
59695999 });
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, "");
59716001 for (current_block.instructions.items) |old_instruction_index| {
59726002 const new_instruction_index: Instruction.Index =
59736003 @enumFromInt(function.instructions.len);
......@@ -6268,10 +6298,10 @@ pub const WipFunction = struct {
62686298 },
62696299 }
62706300 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)
62726302 if (old_instruction_index.hasResultWip(self)) .empty else .none
62736303 else
6274 self.names.items[@intFromEnum(old_instruction_index)]);
6304 self.names.items[@intFromEnum(old_instruction_index)], ".");
62756305
62766306 if (self.debug_locations.get(old_instruction_index)) |location| {
62776307 debug_locations.putAssumeCapacity(new_instruction_index, location);
......@@ -6687,7 +6717,6 @@ pub const Constant = enum(u32) {
66876717 packed_structure,
66886718 array,
66896719 string,
6690 string_null,
66916720 vector,
66926721 splat,
66936722 zeroinitializer,
......@@ -6943,10 +6972,8 @@ pub const Constant = enum(u32) {
69436972 => builder.constantExtraData(Aggregate, item.data).type,
69446973 .splat => builder.constantExtraData(Splat, item.data).type,
69456974 .string,
6946 .string_null,
69476975 => builder.arrayTypeAssumeCapacity(
6948 @as(String, @enumFromInt(item.data)).slice(builder).?.len +
6949 @intFromBool(item.tag == .string_null),
6976 @as(String, @enumFromInt(item.data)).slice(builder).?.len,
69506977 .i8,
69516978 ),
69526979 .blockaddress => builder.ptrTypeAssumeCapacity(
......@@ -7281,13 +7308,9 @@ pub const Constant = enum(u32) {
72817308 }
72827309 try writer.writeByte('>');
72837310 },
7284 inline .string,
7285 .string_null,
7286 => |tag| try writer.print("c{\"" ++ switch (tag) {
7287 .string => "",
7288 .string_null => "@",
7289 else => unreachable,
7290 } ++ "}", .{@as(String, @enumFromInt(item.data)).fmt(data.builder)}),
7311 .string => try writer.print("c{\"}", .{
7312 @as(String, @enumFromInt(item.data)).fmt(data.builder),
7313 }),
72917314 .blockaddress => |tag| {
72927315 const extra = data.builder.constantExtraData(BlockAddress, item.data);
72937316 const function = extra.function.ptrConst(data.builder);
......@@ -7658,7 +7681,7 @@ pub const Metadata = enum(u32) {
76587681 {
76597682 const index = @intFromEnum(metadata) - Metadata.first_forward_reference;
76607683 metadata = builder.metadata_forward_references.items[index];
7661 std.debug.assert(metadata != .none);
7684 assert(metadata != .none);
76627685 }
76637686 return metadata;
76647687 }
......@@ -8058,30 +8081,33 @@ pub const Metadata = enum(u32) {
80588081 }
80598082 },
80608083 .index => |item| try writer.print("!{d}", .{item}),
8061 .value => |item| try Value.format(.{
8062 .value = switch (item.value.unwrap()) {
8063 .instruction, .constant => item.value,
8064 .metadata => |metadata| if (@intFromEnum(metadata) >=
8065 Metadata.first_local_metadata)
8066 item.function.ptrConst(builder).debug_values[
8084 .value => |item| switch (item.value.unwrap()) {
8085 .instruction, .constant => try Value.format(.{
8086 .value = item.value,
8087 .function = item.function,
8088 .builder = builder,
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[
80678094 @intFromEnum(metadata) - Metadata.first_local_metadata
8068 ].toValue()
8069 else if (metadata != .none) {
8070 if (comptime std.mem.eql(u8, fmt_str, "%"))
8071 try writer.print("{%} ", .{Type.metadata.fmt(builder)});
8072 try Metadata.Formatter.format(.{
8073 .formatter = data.formatter,
8074 .item = data.formatter.unwrapAssumeExists(metadata),
8075 }, "", fmt_opts, writer);
8076 return;
8077 } else return,
8095 ].toValue(),
8096 .function = item.function,
8097 .builder = builder,
8098 }, "%", fmt_opts, writer)
8099 else if (metadata != .none) {
8100 if (comptime std.mem.eql(u8, fmt_str, "%"))
8101 try writer.print("{%} ", .{Type.metadata.fmt(builder)});
8102 try Metadata.Formatter.format(.{
8103 .formatter = data.formatter,
8104 .item = data.formatter.unwrapAssumeExists(metadata),
8105 }, "", fmt_opts, writer);
80788106 },
8079 .function = item.function,
8080 .builder = builder,
8081 }, "%", fmt_opts, writer),
8107 },
80828108 .string => |item| try writer.print("{}", .{item.fmt(data.formatter.builder)}),
80838109 inline .bool, .u32, .u64 => |item| try writer.print("{}", .{item}),
8084 .raw => |item| try writer.print("{s}", .{item}),
8110 .raw => |item| try writer.writeAll(item),
80858111 }
80868112 }
80878113 inline fn fmt(formatter: *Formatter, prefix: []const u8, item: anytype) switch (@TypeOf(item)) {
......@@ -8188,7 +8214,7 @@ pub const Metadata = enum(u32) {
81888214 inline for (fields[2..], names) |*field, name| {
81898215 fmt_str = fmt_str ++ "{[" ++ name ++ "]}";
81908216 field.* = .{
8191 .name = name ++ "",
8217 .name = name,
81928218 .type = std.fmt.Formatter(format),
81938219 .default_value = null,
81948220 .is_comptime = false,
......@@ -8305,7 +8331,7 @@ pub fn init(options: Options) Allocator.Error!Builder {
83058331 assert(try self.intConst(.i1, 0) == .false);
83068332 assert(try self.intConst(.i1, 1) == .true);
83078333 assert(try self.noneConst(.token) == .none);
8308 assert(try self.debugNone() == .none);
8334 if (!self.strip) assert(try self.debugNone() == .none);
83098335
83108336 try self.metadata_string_indices.append(self.gpa, 0);
83118337 assert(try self.metadataString("") == .none);
......@@ -8374,19 +8400,22 @@ pub fn finishModuleAsm(self: *Builder) Allocator.Error!void {
83748400}
83758401
83768402pub 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);
83788404 try self.string_indices.ensureUnusedCapacity(self.gpa, 1);
83798405 try self.string_map.ensureUnusedCapacity(self.gpa, 1);
83808406
83818407 const gop = self.string_map.getOrPutAssumeCapacityAdapted(bytes, String.Adapter{ .builder = self });
83828408 if (!gop.found_existing) {
83838409 self.string_bytes.appendSliceAssumeCapacity(bytes);
8384 self.string_bytes.appendAssumeCapacity(0);
83858410 self.string_indices.appendAssumeCapacity(@intCast(self.string_bytes.items.len));
83868411 }
83878412 return String.fromIndex(gop.index);
83888413}
83898414
8415pub fn stringNull(self: *Builder, bytes: [:0]const u8) Allocator.Error!String {
8416 return self.string(bytes[0 .. bytes.len + 1]);
8417}
8418
83908419pub fn stringIfExists(self: *const Builder, bytes: []const u8) ?String {
83918420 return String.fromIndex(
83928421 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 {
83958424
83968425pub fn fmt(self: *Builder, comptime fmt_str: []const u8, fmt_args: anytype) Allocator.Error!String {
83978426 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)));
83998428 try self.string_indices.ensureUnusedCapacity(self.gpa, 1);
84008429 return self.fmtAssumeCapacity(fmt_str, fmt_args);
84018430}
84028431
84038432pub fn fmtAssumeCapacity(self: *Builder, comptime fmt_str: []const u8, fmt_args: anytype) String {
84048433 const start = self.string_bytes.items.len;
8405 self.string_bytes.writer(self.gpa).print(fmt_str ++ .{0}, fmt_args) catch unreachable;
8406 const bytes: []const u8 = self.string_bytes.items[start .. self.string_bytes.items.len - 1];
8434 self.string_bytes.writer(undefined).print(fmt_str, fmt_args) catch unreachable;
8435 const bytes: []const u8 = self.string_bytes.items[start..];
84078436
84088437 const gop = self.string_map.getOrPutAssumeCapacityAdapted(bytes, String.Adapter{ .builder = self });
84098438 if (gop.found_existing) {
......@@ -8468,7 +8497,7 @@ pub fn structType(
84688497pub fn opaqueType(self: *Builder, name: String) Allocator.Error!Type {
84698498 try self.string_map.ensureUnusedCapacity(self.gpa, 1);
84708499 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)});
84728501 try self.string_bytes.ensureUnusedCapacity(self.gpa, id.len + count);
84738502 }
84748503 try self.string_indices.ensureUnusedCapacity(self.gpa, 1);
......@@ -8911,16 +8940,6 @@ pub fn stringValue(self: *Builder, val: String) Allocator.Error!Value {
89118940 return (try self.stringConst(val)).toValue();
89128941}
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
89248943pub fn vectorConst(self: *Builder, ty: Type, vals: []const Constant) Allocator.Error!Constant {
89258944 try self.ensureUnusedConstantCapacity(1, Constant.Aggregate, vals.len);
89268945 return self.vectorConstAssumeCapacity(ty, vals);
......@@ -9354,7 +9373,7 @@ pub fn printUnbuffered(
93549373 defer metadata_formatter.need_comma = undefined;
93559374 try writer.print("{ }{}", .{
93569375 function.alignment,
9357 try metadata_formatter.fmt("!dbg ", global.dbg),
9376 try metadata_formatter.fmt(" !dbg ", global.dbg),
93589377 });
93599378 }
93609379 if (function.instructions.len > 0) {
......@@ -9513,7 +9532,8 @@ pub fn printUnbuffered(
95139532 const name = instruction_index.name(&function);
95149533 if (@intFromEnum(instruction_index) > params_len)
95159534 try writer.writeByte('\n');
9516 try writer.print("{}:", .{name.fmt(self)});
9535 try writer.print("{}:\n", .{name.fmt(self)});
9536 continue;
95179537 },
95189538 .br => |tag| {
95199539 const target: Function.Block.Index = @enumFromInt(instruction.data);
......@@ -9965,6 +9985,7 @@ pub fn printUnbuffered(
99659985 .composite_union_type,
99669986 .composite_enumeration_type,
99679987 .composite_array_type,
9988 .composite_vector_type,
99689989 => |kind| {
99699990 const extra = self.metadataExtraData(Metadata.CompositeType, metadata_item.data);
99709991 try metadata_formatter.specialized(.@"distinct !", .DICompositeType, .{
......@@ -10165,9 +10186,6 @@ pub fn printUnbuffered(
1016510186 .expr = extra.expression,
1016610187 }, writer);
1016710188 },
10168 else => {
10169 try writer.writeByte('\n');
10170 },
1017110189 }
1017210190 }
1017310191 }
......@@ -10206,7 +10224,7 @@ fn printEscapedString(
1020610224fn ensureUnusedGlobalCapacity(self: *Builder, name: String) Allocator.Error!void {
1020710225 try self.string_map.ensureUnusedCapacity(self.gpa, 1);
1020810226 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)});
1021010228 try self.string_bytes.ensureUnusedCapacity(self.gpa, id.len + count);
1021110229 }
1021210230 try self.string_indices.ensureUnusedCapacity(self.gpa, 1);
......@@ -10881,16 +10899,6 @@ fn stringConstAssumeCapacity(self: *Builder, val: String) Constant {
1088110899 return result.constant;
1088210900}
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
1089410902fn vectorConstAssumeCapacity(self: *Builder, ty: Type, vals: []const Constant) Constant {
1089510903 assert(ty.isVector(self));
1089610904 assert(ty.vectorLen(self) == vals.len);
......@@ -11756,8 +11764,8 @@ pub fn metadataStringFmt(self: *Builder, comptime fmt_str: []const u8, fmt_args:
1175611764
1175711765pub fn metadataStringFmtAssumeCapacity(self: *Builder, comptime fmt_str: []const u8, fmt_args: anytype) MetadataString {
1175811766 const start = self.metadata_string_bytes.items.len;
11759 self.metadata_string_bytes.writer(self.gpa).print(fmt_str, fmt_args) catch unreachable;
11760 const bytes: []const u8 = self.metadata_string_bytes.items[start..self.metadata_string_bytes.items.len];
11767 self.metadata_string_bytes.writer(undefined).print(fmt_str, fmt_args) catch unreachable;
11768 const bytes: []const u8 = self.metadata_string_bytes.items[start..];
1176111769
1176211770 const gop = self.metadata_string_map.getOrPutAssumeCapacityAdapted(bytes, String.Adapter{ .builder = self });
1176311771 if (gop.found_existing) {
......@@ -12042,7 +12050,7 @@ pub fn debugEnumerator(
1204212050 bit_width: u32,
1204312051 value: std.math.big.int.Const,
1204412052) Allocator.Error!Metadata {
12045 std.debug.assert(!(unsigned and !value.positive));
12053 assert(!(unsigned and !value.positive));
1204612054 try self.ensureUnusedMetadataCapacity(1, Metadata.Enumerator, 0);
1204712055 try self.metadata_limbs.ensureUnusedCapacity(self.gpa, value.limbs.len);
1204812056 return self.debugEnumeratorAssumeCapacity(name, unsigned, bit_width, value);
......@@ -12147,7 +12155,7 @@ pub fn debugConstant(self: *Builder, value: Constant) Allocator.Error!Metadata {
1214712155}
1214812156
1214912157pub fn debugForwardReferenceSetType(self: *Builder, fwd_ref: Metadata, ty: Metadata) void {
12150 std.debug.assert(
12158 assert(
1215112159 @intFromEnum(fwd_ref) >= Metadata.first_forward_reference and
1215212160 @intFromEnum(fwd_ref) <= Metadata.first_local_metadata,
1215312161 );
......@@ -12226,7 +12234,8 @@ fn metadataDistinctAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anyt
1222612234}
1222712235
1222812236fn debugNamedAssumeCapacity(self: *Builder, name: MetadataString, operands: []const Metadata) void {
12229 std.debug.assert(name != .none);
12237 assert(!self.strip);
12238 assert(name != .none);
1223012239 const extra_index: u32 = @intCast(self.metadata_extra.items.len);
1223112240 self.metadata_extra.appendSliceAssumeCapacity(@ptrCast(operands));
1223212241
......@@ -12238,6 +12247,7 @@ fn debugNamedAssumeCapacity(self: *Builder, name: MetadataString, operands: []co
1223812247}
1223912248
1224012249pub fn debugNoneAssumeCapacity(self: *Builder) Metadata {
12250 assert(!self.strip);
1224112251 return self.metadataSimpleAssumeCapacity(.none, .{});
1224212252}
1224312253
......@@ -12246,6 +12256,7 @@ fn debugFileAssumeCapacity(
1224612256 filename: MetadataString,
1224712257 directory: MetadataString,
1224812258) Metadata {
12259 assert(!self.strip);
1224912260 return self.metadataDistinctAssumeCapacity(.file, Metadata.File{
1225012261 .filename = filename,
1225112262 .directory = directory,
......@@ -12260,6 +12271,7 @@ pub fn debugCompileUnitAssumeCapacity(
1226012271 globals: Metadata,
1226112272 options: Metadata.CompileUnit.Options,
1226212273) Metadata {
12274 assert(!self.strip);
1226312275 return self.metadataDistinctAssumeCapacity(
1226412276 if (options.optimized) .@"compile_unit optimized" else .compile_unit,
1226512277 Metadata.CompileUnit{
......@@ -12282,6 +12294,7 @@ fn debugSubprogramAssumeCapacity(
1228212294 options: Metadata.Subprogram.Options,
1228312295 compile_unit: Metadata,
1228412296) Metadata {
12297 assert(!self.strip);
1228512298 const tag: Metadata.Tag = @enumFromInt(@intFromEnum(Metadata.Tag.subprogram) +
1228612299 @as(u3, @truncate(@as(u32, @bitCast(options.sp_flags)) >> 2)));
1228712300 return self.metadataDistinctAssumeCapacity(tag, Metadata.Subprogram{
......@@ -12297,6 +12310,7 @@ fn debugSubprogramAssumeCapacity(
1229712310}
1229812311
1229912312fn debugLexicalBlockAssumeCapacity(self: *Builder, scope: Metadata, file: Metadata, line: u32, column: u32) Metadata {
12313 assert(!self.strip);
1230012314 return self.metadataDistinctAssumeCapacity(.lexical_block, Metadata.LexicalBlock{
1230112315 .scope = scope,
1230212316 .file = file,
......@@ -12306,6 +12320,7 @@ fn debugLexicalBlockAssumeCapacity(self: *Builder, scope: Metadata, file: Metada
1230612320}
1230712321
1230812322fn debugLocationAssumeCapacity(self: *Builder, line: u32, column: u32, scope: Metadata, inlined_at: Metadata) Metadata {
12323 assert(!self.strip);
1230912324 return self.metadataSimpleAssumeCapacity(.location, Metadata.Location{
1231012325 .line = line,
1231112326 .column = column,
......@@ -12315,6 +12330,7 @@ fn debugLocationAssumeCapacity(self: *Builder, line: u32, column: u32, scope: Me
1231512330}
1231612331
1231712332fn debugBoolTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bits: u64) Metadata {
12333 assert(!self.strip);
1231812334 return self.metadataDistinctAssumeCapacity(.basic_bool_type, Metadata.BasicType{
1231912335 .name = name,
1232012336 .size_in_bits_lo = @truncate(size_in_bits),
......@@ -12323,6 +12339,7 @@ fn debugBoolTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bit
1232312339}
1232412340
1232512341fn debugUnsignedTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bits: u64) Metadata {
12342 assert(!self.strip);
1232612343 return self.metadataDistinctAssumeCapacity(.basic_unsigned_type, Metadata.BasicType{
1232712344 .name = name,
1232812345 .size_in_bits_lo = @truncate(size_in_bits),
......@@ -12331,6 +12348,7 @@ fn debugUnsignedTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in
1233112348}
1233212349
1233312350fn debugSignedTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bits: u64) Metadata {
12351 assert(!self.strip);
1233412352 return self.metadataDistinctAssumeCapacity(.basic_signed_type, Metadata.BasicType{
1233512353 .name = name,
1233612354 .size_in_bits_lo = @truncate(size_in_bits),
......@@ -12339,6 +12357,7 @@ fn debugSignedTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_b
1233912357}
1234012358
1234112359fn debugFloatTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bits: u64) Metadata {
12360 assert(!self.strip);
1234212361 return self.metadataDistinctAssumeCapacity(.basic_float_type, Metadata.BasicType{
1234312362 .name = name,
1234412363 .size_in_bits_lo = @truncate(size_in_bits),
......@@ -12347,6 +12366,7 @@ fn debugFloatTypeAssumeCapacity(self: *Builder, name: MetadataString, size_in_bi
1234712366}
1234812367
1234912368fn debugForwardReferenceAssumeCapacity(self: *Builder) Metadata {
12369 assert(!self.strip);
1235012370 const index = Metadata.first_forward_reference + self.metadata_forward_references.items.len;
1235112371 self.metadata_forward_references.appendAssumeCapacity(.none);
1235212372 return @enumFromInt(index);
......@@ -12363,6 +12383,7 @@ fn debugStructTypeAssumeCapacity(
1236312383 align_in_bits: u64,
1236412384 fields_tuple: Metadata,
1236512385) Metadata {
12386 assert(!self.strip);
1236612387 return self.debugCompositeTypeAssumeCapacity(
1236712388 .composite_struct_type,
1236812389 name,
......@@ -12387,6 +12408,7 @@ fn debugUnionTypeAssumeCapacity(
1238712408 align_in_bits: u64,
1238812409 fields_tuple: Metadata,
1238912410) Metadata {
12411 assert(!self.strip);
1239012412 return self.debugCompositeTypeAssumeCapacity(
1239112413 .composite_union_type,
1239212414 name,
......@@ -12411,6 +12433,7 @@ fn debugEnumerationTypeAssumeCapacity(
1241112433 align_in_bits: u64,
1241212434 fields_tuple: Metadata,
1241312435) Metadata {
12436 assert(!self.strip);
1241412437 return self.debugCompositeTypeAssumeCapacity(
1241512438 .composite_enumeration_type,
1241612439 name,
......@@ -12435,6 +12458,7 @@ fn debugArrayTypeAssumeCapacity(
1243512458 align_in_bits: u64,
1243612459 fields_tuple: Metadata,
1243712460) Metadata {
12461 assert(!self.strip);
1243812462 return self.debugCompositeTypeAssumeCapacity(
1243912463 .composite_array_type,
1244012464 name,
......@@ -12459,6 +12483,7 @@ fn debugVectorTypeAssumeCapacity(
1245912483 align_in_bits: u64,
1246012484 fields_tuple: Metadata,
1246112485) Metadata {
12486 assert(!self.strip);
1246212487 return self.debugCompositeTypeAssumeCapacity(
1246312488 .composite_vector_type,
1246412489 name,
......@@ -12484,6 +12509,7 @@ fn debugCompositeTypeAssumeCapacity(
1248412509 align_in_bits: u64,
1248512510 fields_tuple: Metadata,
1248612511) Metadata {
12512 assert(!self.strip);
1248712513 return self.metadataDistinctAssumeCapacity(tag, Metadata.CompositeType{
1248812514 .name = name,
1248912515 .file = file,
......@@ -12509,6 +12535,7 @@ fn debugPointerTypeAssumeCapacity(
1250912535 align_in_bits: u64,
1251012536 offset_in_bits: u64,
1251112537) Metadata {
12538 assert(!self.strip);
1251212539 return self.metadataDistinctAssumeCapacity(.derived_pointer_type, Metadata.DerivedType{
1251312540 .name = name,
1251412541 .file = file,
......@@ -12535,6 +12562,7 @@ fn debugMemberTypeAssumeCapacity(
1253512562 align_in_bits: u64,
1253612563 offset_in_bits: u64,
1253712564) Metadata {
12565 assert(!self.strip);
1253812566 return self.metadataDistinctAssumeCapacity(.derived_member_type, Metadata.DerivedType{
1253912567 .name = name,
1254012568 .file = file,
......@@ -12554,6 +12582,7 @@ fn debugSubroutineTypeAssumeCapacity(
1255412582 self: *Builder,
1255512583 types_tuple: Metadata,
1255612584) Metadata {
12585 assert(!self.strip);
1255712586 return self.metadataDistinctAssumeCapacity(.subroutine_type, Metadata.SubroutineType{
1255812587 .types_tuple = types_tuple,
1255912588 });
......@@ -12566,6 +12595,7 @@ fn debugEnumeratorAssumeCapacity(
1256612595 bit_width: u32,
1256712596 value: std.math.big.int.Const,
1256812597) Metadata {
12598 assert(!self.strip);
1256912599 const Key = struct { tag: Metadata.Tag, index: Metadata };
1257012600 const Adapter = struct {
1257112601 pub fn hash(_: @This(), key: Key) u32 {
......@@ -12587,7 +12617,7 @@ fn debugEnumeratorAssumeCapacity(
1258712617 else
1258812618 .enumerator_signed_negative;
1258912619
12590 std.debug.assert(!(tag == .enumerator_unsigned and !value.positive));
12620 assert(!(tag == .enumerator_unsigned and !value.positive));
1259112621
1259212622 const gop = self.metadata_map.getOrPutAssumeCapacityAdapted(
1259312623 Key{ .tag = tag, .index = @enumFromInt(self.metadata_map.count()) },
......@@ -12616,6 +12646,7 @@ fn debugSubrangeAssumeCapacity(
1261612646 lower_bound: Metadata,
1261712647 count: Metadata,
1261812648) Metadata {
12649 assert(!self.strip);
1261912650 return self.metadataDistinctAssumeCapacity(.subrange, Metadata.Subrange{
1262012651 .lower_bound = lower_bound,
1262112652 .count = count,
......@@ -12626,6 +12657,7 @@ fn debugExpressionAssumeCapacity(
1262612657 self: *Builder,
1262712658 elements: []const u32,
1262812659) Metadata {
12660 assert(!self.strip);
1262912661 const Key = struct {
1263012662 elements: []const u32,
1263112663 };
......@@ -12672,6 +12704,7 @@ fn debugTupleAssumeCapacity(
1267212704 self: *Builder,
1267312705 elements: []const Metadata,
1267412706) Metadata {
12707 assert(!self.strip);
1267512708 const Key = struct {
1267612709 elements: []const Metadata,
1267712710 };
......@@ -12720,6 +12753,7 @@ fn debugModuleFlagAssumeCapacity(
1272012753 name: MetadataString,
1272112754 constant: Metadata,
1272212755) Metadata {
12756 assert(!self.strip);
1272312757 return self.metadataSimpleAssumeCapacity(.module_flag, Metadata.ModuleFlag{
1272412758 .behavior = behavior,
1272512759 .name = name,
......@@ -12734,7 +12768,8 @@ fn debugLocalVarAssumeCapacity(
1273412768 scope: Metadata,
1273512769 line: u32,
1273612770 ty: Metadata,
12737) Allocator.Error!Metadata {
12771) Metadata {
12772 assert(!self.strip);
1273812773 return self.metadataDistinctAssumeCapacity(.local_var, Metadata.LocalVar{
1273912774 .name = name,
1274012775 .file = file,
......@@ -12752,7 +12787,8 @@ fn debugParameterAssumeCapacity(
1275212787 line: u32,
1275312788 ty: Metadata,
1275412789 arg_no: u32,
12755) Allocator.Error!Metadata {
12790) Metadata {
12791 assert(!self.strip);
1275612792 return self.metadataDistinctAssumeCapacity(.parameter, Metadata.Parameter{
1275712793 .name = name,
1275812794 .file = file,
......@@ -12773,7 +12809,8 @@ fn debugGlobalVarAssumeCapacity(
1277312809 ty: Metadata,
1277412810 variable: Variable.Index,
1277512811 options: Metadata.GlobalVar.Options,
12776) Allocator.Error!Metadata {
12812) Metadata {
12813 assert(!self.strip);
1277712814 return self.metadataDistinctAssumeCapacity(
1277812815 if (options.local) .@"global_var local" else .global_var,
1277912816 Metadata.GlobalVar{
......@@ -12793,6 +12830,7 @@ fn debugGlobalVarExpressionAssumeCapacity(
1279312830 variable: Metadata,
1279412831 expression: Metadata,
1279512832) Metadata {
12833 assert(!self.strip);
1279612834 return self.metadataDistinctAssumeCapacity(.global_var_expression, Metadata.GlobalVarExpression{
1279712835 .variable = variable,
1279812836 .expression = expression,
......@@ -12800,6 +12838,7 @@ fn debugGlobalVarExpressionAssumeCapacity(
1280012838}
1280112839
1280212840fn debugConstantAssumeCapacity(self: *Builder, constant: Constant) Metadata {
12841 assert(!self.strip);
1280312842 const Adapter = struct {
1280412843 builder: *const Builder,
1280512844 pub fn hash(_: @This(), key: Constant) u32 {
......@@ -13528,18 +13567,16 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1352813567 }
1352913568 },
1353013569 .string,
13531 .string_null,
1353213570 => {
1353313571 const str: String = @enumFromInt(data);
1353413572 if (str == .none) {
1353513573 try constants_block.writeAbbrev(Constants.Null{});
1353613574 } else {
1353713575 const slice = str.slice(self) orelse unreachable;
13538 switch (tags[index]) {
13539 .string => try constants_block.writeAbbrev(Constants.String{ .string = slice }),
13540 .string_null => try constants_block.writeAbbrev(Constants.CString{ .string = slice }),
13541 else => unreachable,
13542 }
13576 if (slice.len > 0 and slice[slice.len - 1] == 0)
13577 try constants_block.writeAbbrev(Constants.CString{ .string = slice[0 .. slice.len - 1] })
13578 else
13579 try constants_block.writeAbbrev(Constants.String{ .string = slice });
1354313580 }
1354413581 },
1354513582 .bitcast,
......@@ -13918,7 +13955,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1391813955 },
1391913956 .location => {
1392013957 const extra = self.metadataExtraData(Metadata.Location, data);
13921 std.debug.assert(extra.scope != .none);
13958 assert(extra.scope != .none);
1392213959 try metadata_block.writeAbbrev(MetadataBlock.Location{
1392313960 .line = extra.line,
1392413961 .column = extra.column,