authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-07-21 02:44:58-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-07-21 02:44:58-07:00
logf303c3943f188b76c6d2566bd65429a8b60e8a59
tree72bc31b2923544e0308abe815be89356de65bcc3
parentd484269543c571454818599cce0460f9b363631f

Revert "Merge pull request #20380 from tau-dev/master"

This reverts commit 397be0c9cc8156d38d1487a4c80210007033cbd0, reversing changes made to 18d412ab2fb7bda92f7bfbdf732849bbcd066c33. Caused test failures in master branch.

5 files changed, 483 insertions(+), 716 deletions(-)

lib/std/debug.zig+1-12
...@@ -2459,24 +2459,13 @@ pub const ModuleDebugInfo = switch (native_os) {...@@ -2459,24 +2459,13 @@ pub const ModuleDebugInfo = switch (native_os) {
2459 module,2459 module,
2460 relocated_address - coff_section.virtual_address,2460 relocated_address - coff_section.virtual_address,
2461 ) orelse "???";2461 ) orelse "???";
2462 // While DWARF gets us just the function's own name, the PDB
2463 // stores it qualified with its namespace by the C++ `::`
2464 // operator. We can strip that for consistency; the
2465 // SymbolInfo will contain the line number, which is a more
2466 // language-neutral way of distinguishing same-named symbols
2467 // anyway.
2468 const symbol_simple_name = if (mem.indexOf(u8, symbol_name, "::")) |cpp_namespace|
2469 symbol_name[cpp_namespace + 2 ..]
2470 else
2471 symbol_name;
2472
2473 const opt_line_info = try self.pdb.?.getLineNumberInfo(2462 const opt_line_info = try self.pdb.?.getLineNumberInfo(
2474 module,2463 module,
2475 relocated_address - coff_section.virtual_address,2464 relocated_address - coff_section.virtual_address,
2476 );2465 );
24772466
2478 return SymbolInfo{2467 return SymbolInfo{
2479 .symbol_name = symbol_simple_name,2468 .symbol_name = symbol_name,
2480 .compile_unit_name = obj_basename,2469 .compile_unit_name = obj_basename,
2481 .line_info = opt_line_info,2470 .line_info = opt_line_info,
2482 };2471 };
src/codegen/llvm.zig+457-504
...@@ -806,17 +806,14 @@ pub const Object = struct {...@@ -806,17 +806,14 @@ pub const Object = struct {
806806
807 debug_enums_fwd_ref: Builder.Metadata,807 debug_enums_fwd_ref: Builder.Metadata,
808 debug_globals_fwd_ref: Builder.Metadata,808 debug_globals_fwd_ref: Builder.Metadata,
809 debug_imports_fwd_ref: Builder.Metadata,
810809
811 debug_enums: std.ArrayListUnmanaged(Builder.Metadata),810 debug_enums: std.ArrayListUnmanaged(Builder.Metadata),
812 debug_globals: std.ArrayListUnmanaged(Builder.Metadata),811 debug_globals: std.ArrayListUnmanaged(Builder.Metadata),
813 debug_imports: std.ArrayListUnmanaged(Builder.Metadata),
814812
815 debug_file_map: std.AutoHashMapUnmanaged(*const Zcu.File, Builder.Metadata),813 debug_file_map: std.AutoHashMapUnmanaged(*const Zcu.File, Builder.Metadata),
816 debug_type_map: std.AutoHashMapUnmanaged(Type, Builder.Metadata),814 debug_type_map: std.AutoHashMapUnmanaged(Type, Builder.Metadata),
817815
818 // The value says whether this namespace's type is runtime-required.816 debug_unresolved_namespace_scopes: std.AutoArrayHashMapUnmanaged(InternPool.NamespaceIndex, Builder.Metadata),
819 debug_unresolved_namespace_scopes: std.AutoArrayHashMapUnmanaged(Type, bool),
820817
821 target: std.Target,818 target: std.Target,
822 /// Ideally we would use `llvm_module.getNamedFunction` to go from *Decl to LLVM function,819 /// Ideally we would use `llvm_module.getNamedFunction` to go from *Decl to LLVM function,
...@@ -881,7 +878,7 @@ pub const Object = struct {...@@ -881,7 +878,7 @@ pub const Object = struct {
881878
882 builder.data_layout = try builder.fmt("{}", .{DataLayoutBuilder{ .target = target }});879 builder.data_layout = try builder.fmt("{}", .{DataLayoutBuilder{ .target = target }});
883880
884 const debug_compile_unit, const debug_enums_fwd_ref, const debug_globals_fwd_ref, const debug_imports_fwd_ref =881 const debug_compile_unit, const debug_enums_fwd_ref, const debug_globals_fwd_ref =
885 if (!builder.strip)882 if (!builder.strip)
886 debug_info: {883 debug_info: {
887 // We fully resolve all paths at this point to avoid lack of884 // We fully resolve all paths at this point to avoid lack of
...@@ -913,7 +910,6 @@ pub const Object = struct {...@@ -913,7 +910,6 @@ pub const Object = struct {
913910
914 const debug_enums_fwd_ref = try builder.debugForwardReference();911 const debug_enums_fwd_ref = try builder.debugForwardReference();
915 const debug_globals_fwd_ref = try builder.debugForwardReference();912 const debug_globals_fwd_ref = try builder.debugForwardReference();
916 const debug_imports_fwd_ref = try builder.debugForwardReference();
917913
918 const debug_compile_unit = try builder.debugCompileUnit(914 const debug_compile_unit = try builder.debugCompileUnit(
919 debug_file,915 debug_file,
...@@ -926,7 +922,6 @@ pub const Object = struct {...@@ -926,7 +922,6 @@ pub const Object = struct {
926 }),922 }),
927 debug_enums_fwd_ref,923 debug_enums_fwd_ref,
928 debug_globals_fwd_ref,924 debug_globals_fwd_ref,
929 debug_imports_fwd_ref,
930 .{ .optimized = comp.root_mod.optimize_mode != .Debug },925 .{ .optimized = comp.root_mod.optimize_mode != .Debug },
931 );926 );
932927
...@@ -982,8 +977,8 @@ pub const Object = struct {...@@ -982,8 +977,8 @@ pub const Object = struct {
982 }977 }
983978
984 try builder.debugNamed(try builder.metadataString("llvm.dbg.cu"), &.{debug_compile_unit});979 try builder.debugNamed(try builder.metadataString("llvm.dbg.cu"), &.{debug_compile_unit});
985 break :debug_info .{ debug_compile_unit, debug_enums_fwd_ref, debug_globals_fwd_ref, debug_imports_fwd_ref };980 break :debug_info .{ debug_compile_unit, debug_enums_fwd_ref, debug_globals_fwd_ref };
986 } else .{.none} ** 4;981 } else .{.none} ** 3;
987982
988 const obj = try arena.create(Object);983 const obj = try arena.create(Object);
989 obj.* = .{984 obj.* = .{
...@@ -996,10 +991,8 @@ pub const Object = struct {...@@ -996,10 +991,8 @@ pub const Object = struct {
996 .debug_compile_unit = debug_compile_unit,991 .debug_compile_unit = debug_compile_unit,
997 .debug_enums_fwd_ref = debug_enums_fwd_ref,992 .debug_enums_fwd_ref = debug_enums_fwd_ref,
998 .debug_globals_fwd_ref = debug_globals_fwd_ref,993 .debug_globals_fwd_ref = debug_globals_fwd_ref,
999 .debug_imports_fwd_ref = debug_imports_fwd_ref,
1000 .debug_enums = .{},994 .debug_enums = .{},
1001 .debug_globals = .{},995 .debug_globals = .{},
1002 .debug_imports = .{},
1003 .debug_file_map = .{},996 .debug_file_map = .{},
1004 .debug_type_map = .{},997 .debug_type_map = .{},
1005 .debug_unresolved_namespace_scopes = .{},998 .debug_unresolved_namespace_scopes = .{},
...@@ -1141,7 +1134,18 @@ pub const Object = struct {...@@ -1141,7 +1134,18 @@ pub const Object = struct {
1141 try self.genModuleLevelAssembly();1134 try self.genModuleLevelAssembly();
11421135
1143 if (!self.builder.strip) {1136 if (!self.builder.strip) {
1144 try self.genNamespaces();1137 {
1138 var i: usize = 0;
1139 while (i < self.debug_unresolved_namespace_scopes.count()) : (i += 1) {
1140 const namespace_index = self.debug_unresolved_namespace_scopes.keys()[i];
1141 const fwd_ref = self.debug_unresolved_namespace_scopes.values()[i];
1142
1143 const namespace = zcu.namespacePtr(namespace_index);
1144 const debug_type = try self.lowerDebugType(namespace.getType(zcu));
1145
1146 self.builder.debugForwardReferenceSetType(fwd_ref, debug_type);
1147 }
1148 }
11451149
1146 self.builder.debugForwardReferenceSetType(1150 self.builder.debugForwardReferenceSetType(
1147 self.debug_enums_fwd_ref,1151 self.debug_enums_fwd_ref,
...@@ -1152,11 +1156,6 @@ pub const Object = struct {...@@ -1152,11 +1156,6 @@ pub const Object = struct {
1152 self.debug_globals_fwd_ref,1156 self.debug_globals_fwd_ref,
1153 try self.builder.debugTuple(self.debug_globals.items),1157 try self.builder.debugTuple(self.debug_globals.items),
1154 );1158 );
1155
1156 self.builder.debugForwardReferenceSetType(
1157 self.debug_imports_fwd_ref,
1158 try self.builder.debugTuple(self.debug_imports.items),
1159 );
1160 }1159 }
1161 }1160 }
11621161
...@@ -1636,19 +1635,15 @@ pub const Object = struct {...@@ -1636,19 +1635,15 @@ pub const Object = struct {
16361635
1637 const file, const subprogram = if (!wip.strip) debug_info: {1636 const file, const subprogram = if (!wip.strip) debug_info: {
1638 const file = try o.getDebugFile(file_scope);1637 const file = try o.getDebugFile(file_scope);
1639 const scope = try o.lowerDebugType(zcu.declPtr(namespace.decl_index).val.toType(), false);
16401638
1641 const line_number = decl.navSrcLine(zcu) + 1;1639 const line_number = decl.navSrcLine(zcu) + 1;
1642 const is_internal_linkage = decl.val.getExternFunc(zcu) == null;1640 const is_internal_linkage = decl.val.getExternFunc(zcu) == null;
1643 const debug_decl_type = try o.lowerDebugType(decl.typeOf(zcu), true);1641 const debug_decl_type = try o.lowerDebugType(decl.typeOf(zcu));
1644 const decl_name = try o.builder.metadataString(decl.name.toSlice(ip));
1645 const link_name = try o.builder.metadataStringFromStrtabString(function_index.name(&o.builder));
16461642
1647 const subprogram = try o.builder.debugSubprogram(1643 const subprogram = try o.builder.debugSubprogram(
1648 file,1644 file,
1649 scope,1645 try o.builder.metadataString(decl.name.toSlice(ip)),
1650 decl_name,1646 try o.builder.metadataStringFromStrtabString(function_index.name(&o.builder)),
1651 link_name,
1652 line_number,1647 line_number,
1653 line_number + func.lbrace_line,1648 line_number + func.lbrace_line,
1654 debug_decl_type,1649 debug_decl_type,
...@@ -1665,7 +1660,6 @@ pub const Object = struct {...@@ -1665,7 +1660,6 @@ pub const Object = struct {
1665 },1660 },
1666 o.debug_compile_unit,1661 o.debug_compile_unit,
1667 );1662 );
1668
1669 function_index.setSubprogram(subprogram, &o.builder);1663 function_index.setSubprogram(subprogram, &o.builder);
1670 break :debug_info .{ file, subprogram };1664 break :debug_info .{ file, subprogram };
1671 } else .{.none} ** 2;1665 } else .{.none} ** 2;
...@@ -1913,7 +1907,6 @@ pub const Object = struct {...@@ -1913,7 +1907,6 @@ pub const Object = struct {
1913 pub fn lowerDebugType(1907 pub fn lowerDebugType(
1914 o: *Object,1908 o: *Object,
1915 ty: Type,1909 ty: Type,
1916 required_by_runtime: bool,
1917 ) Allocator.Error!Builder.Metadata {1910 ) Allocator.Error!Builder.Metadata {
1918 assert(!o.builder.strip);1911 assert(!o.builder.strip);
19191912
...@@ -1923,13 +1916,7 @@ pub const Object = struct {...@@ -1923,13 +1916,7 @@ pub const Object = struct {
1923 const zcu = pt.zcu;1916 const zcu = pt.zcu;
1924 const ip = &zcu.intern_pool;1917 const ip = &zcu.intern_pool;
19251918
1926 if (o.debug_type_map.get(ty)) |debug_type| {1919 if (o.debug_type_map.get(ty)) |debug_type| return debug_type;
1927 if (required_by_runtime) {
1928 if (o.debug_unresolved_namespace_scopes.getEntry(ty)) |entry|
1929 entry.value_ptr.* = true;
1930 }
1931 return debug_type;
1932 }
19331920
1934 switch (ty.zigTypeTag(zcu)) {1921 switch (ty.zigTypeTag(zcu)) {
1935 .Void,1922 .Void,
...@@ -1944,9 +1931,10 @@ pub const Object = struct {...@@ -1944,9 +1931,10 @@ pub const Object = struct {
1944 },1931 },
1945 .Int => {1932 .Int => {
1946 const info = ty.intInfo(zcu);1933 const info = ty.intInfo(zcu);
1947 const int_name = try o.allocTypeName(ty);1934 assert(info.bits != 0);
1948 defer gpa.free(int_name);1935 const name = try o.allocTypeName(ty);
1949 const builder_name = try o.builder.metadataString(int_name);1936 defer gpa.free(name);
1937 const builder_name = try o.builder.metadataString(name);
1950 const debug_bits = ty.abiSize(pt) * 8; // lldb cannot handle non-byte sized types1938 const debug_bits = ty.abiSize(pt) * 8; // lldb cannot handle non-byte sized types
1951 const debug_int_type = switch (info.signedness) {1939 const debug_int_type = switch (info.signedness) {
1952 .signed => try o.builder.debugSignedType(builder_name, debug_bits),1940 .signed => try o.builder.debugSignedType(builder_name, debug_bits),
...@@ -1955,12 +1943,68 @@ pub const Object = struct {...@@ -1955,12 +1943,68 @@ pub const Object = struct {
1955 try o.debug_type_map.put(gpa, ty, debug_int_type);1943 try o.debug_type_map.put(gpa, ty, debug_int_type);
1956 return debug_int_type;1944 return debug_int_type;
1957 },1945 },
1946 .Enum => {
1947 const owner_decl_index = ty.getOwnerDecl(zcu);
1948 const owner_decl = zcu.declPtr(owner_decl_index);
1949
1950 if (!ty.hasRuntimeBitsIgnoreComptime(pt)) {
1951 const debug_enum_type = try o.makeEmptyNamespaceDebugType(owner_decl_index);
1952 try o.debug_type_map.put(gpa, ty, debug_enum_type);
1953 return debug_enum_type;
1954 }
1955
1956 const enum_type = ip.loadEnumType(ty.toIntern());
1957
1958 const enumerators = try gpa.alloc(Builder.Metadata, enum_type.names.len);
1959 defer gpa.free(enumerators);
1960
1961 const int_ty = Type.fromInterned(enum_type.tag_ty);
1962 const int_info = ty.intInfo(zcu);
1963 assert(int_info.bits != 0);
1964
1965 for (enum_type.names.get(ip), 0..) |field_name_ip, i| {
1966 var bigint_space: Value.BigIntSpace = undefined;
1967 const bigint = if (enum_type.values.len != 0)
1968 Value.fromInterned(enum_type.values.get(ip)[i]).toBigInt(&bigint_space, pt)
1969 else
1970 std.math.big.int.Mutable.init(&bigint_space.limbs, i).toConst();
1971
1972 enumerators[i] = try o.builder.debugEnumerator(
1973 try o.builder.metadataString(field_name_ip.toSlice(ip)),
1974 int_info.signedness == .unsigned,
1975 int_info.bits,
1976 bigint,
1977 );
1978 }
1979
1980 const file_scope = zcu.namespacePtr(owner_decl.src_namespace).fileScope(zcu);
1981 const file = try o.getDebugFile(file_scope);
1982 const scope = try o.namespaceToDebugScope(owner_decl.src_namespace);
1983
1984 const name = try o.allocTypeName(ty);
1985 defer gpa.free(name);
1986
1987 const debug_enum_type = try o.builder.debugEnumerationType(
1988 try o.builder.metadataString(name),
1989 file,
1990 scope,
1991 owner_decl.typeSrcLine(zcu) + 1, // Line
1992 try o.lowerDebugType(int_ty),
1993 ty.abiSize(pt) * 8,
1994 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
1995 try o.builder.debugTuple(enumerators),
1996 );
1997
1998 try o.debug_type_map.put(gpa, ty, debug_enum_type);
1999 try o.debug_enums.append(gpa, debug_enum_type);
2000 return debug_enum_type;
2001 },
1958 .Float => {2002 .Float => {
1959 const bits = ty.floatBits(target);2003 const bits = ty.floatBits(target);
1960 const float_name = try o.allocTypeName(ty);2004 const name = try o.allocTypeName(ty);
1961 defer gpa.free(float_name);2005 defer gpa.free(name);
1962 const debug_float_type = try o.builder.debugFloatType(2006 const debug_float_type = try o.builder.debugFloatType(
1963 try o.builder.metadataString(float_name),2007 try o.builder.metadataString(name),
1964 bits,2008 bits,
1965 );2009 );
1966 try o.debug_type_map.put(gpa, ty, debug_float_type);2010 try o.debug_type_map.put(gpa, ty, debug_float_type);
...@@ -2002,7 +2046,7 @@ pub const Object = struct {...@@ -2002,7 +2046,7 @@ pub const Object = struct {
2002 },2046 },
2003 },2047 },
2004 });2048 });
2005 const debug_ptr_type = try o.lowerDebugType(bland_ptr_ty, required_by_runtime);2049 const debug_ptr_type = try o.lowerDebugType(bland_ptr_ty);
2006 try o.debug_type_map.put(gpa, ty, debug_ptr_type);2050 try o.debug_type_map.put(gpa, ty, debug_ptr_type);
2007 return debug_ptr_type;2051 return debug_ptr_type;
2008 }2052 }
...@@ -2018,7 +2062,6 @@ pub const Object = struct {...@@ -2018,7 +2062,6 @@ pub const Object = struct {
20182062
2019 const name = try o.allocTypeName(ty);2063 const name = try o.allocTypeName(ty);
2020 defer gpa.free(name);2064 defer gpa.free(name);
2021
2022 const line = 0;2065 const line = 0;
20232066
2024 const ptr_size = ptr_ty.abiSize(pt);2067 const ptr_size = ptr_ty.abiSize(pt);
...@@ -2033,7 +2076,7 @@ pub const Object = struct {...@@ -2033,7 +2076,7 @@ pub const Object = struct {
2033 .none, // File2076 .none, // File
2034 debug_fwd_ref,2077 debug_fwd_ref,
2035 0, // Line2078 0, // Line
2036 try o.lowerDebugType(ptr_ty, required_by_runtime),2079 try o.lowerDebugType(ptr_ty),
2037 ptr_size * 8,2080 ptr_size * 8,
2038 (ptr_align.toByteUnits() orelse 0) * 8,2081 (ptr_align.toByteUnits() orelse 0) * 8,
2039 0, // Offset2082 0, // Offset
...@@ -2044,7 +2087,7 @@ pub const Object = struct {...@@ -2044,7 +2087,7 @@ pub const Object = struct {
2044 .none, // File2087 .none, // File
2045 debug_fwd_ref,2088 debug_fwd_ref,
2046 0, // Line2089 0, // Line
2047 try o.lowerDebugType(len_ty, required_by_runtime),2090 try o.lowerDebugType(len_ty),
2048 len_size * 8,2091 len_size * 8,
2049 (len_align.toByteUnits() orelse 0) * 8,2092 (len_align.toByteUnits() orelse 0) * 8,
2050 len_offset * 8,2093 len_offset * 8,
...@@ -2062,7 +2105,6 @@ pub const Object = struct {...@@ -2062,7 +2105,6 @@ pub const Object = struct {
2062 debug_ptr_type,2105 debug_ptr_type,
2063 debug_len_type,2106 debug_len_type,
2064 }),2107 }),
2065 isByRef(ty, pt),
2066 );2108 );
20672109
2068 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_slice_type);2110 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_slice_type);
...@@ -2074,7 +2116,7 @@ pub const Object = struct {...@@ -2074,7 +2116,7 @@ pub const Object = struct {
2074 return debug_slice_type;2116 return debug_slice_type;
2075 }2117 }
20762118
2077 const debug_elem_ty = try o.lowerDebugType(Type.fromInterned(ptr_info.child), required_by_runtime);2119 const debug_elem_ty = try o.lowerDebugType(Type.fromInterned(ptr_info.child));
20782120
2079 const name = try o.allocTypeName(ty);2121 const name = try o.allocTypeName(ty);
2080 defer gpa.free(name);2122 defer gpa.free(name);
...@@ -2098,13 +2140,41 @@ pub const Object = struct {...@@ -2098,13 +2140,41 @@ pub const Object = struct {
20982140
2099 return debug_ptr_type;2141 return debug_ptr_type;
2100 },2142 },
2143 .Opaque => {
2144 if (ty.toIntern() == .anyopaque_type) {
2145 const debug_opaque_type = try o.builder.debugSignedType(
2146 try o.builder.metadataString("anyopaque"),
2147 0,
2148 );
2149 try o.debug_type_map.put(gpa, ty, debug_opaque_type);
2150 return debug_opaque_type;
2151 }
2152
2153 const name = try o.allocTypeName(ty);
2154 defer gpa.free(name);
2155 const owner_decl_index = ty.getOwnerDecl(zcu);
2156 const owner_decl = zcu.declPtr(owner_decl_index);
2157 const file_scope = zcu.namespacePtr(owner_decl.src_namespace).fileScope(zcu);
2158 const debug_opaque_type = try o.builder.debugStructType(
2159 try o.builder.metadataString(name),
2160 try o.getDebugFile(file_scope),
2161 try o.namespaceToDebugScope(owner_decl.src_namespace),
2162 owner_decl.typeSrcLine(zcu) + 1, // Line
2163 .none, // Underlying type
2164 0, // Size
2165 0, // Align
2166 .none, // Fields
2167 );
2168 try o.debug_type_map.put(gpa, ty, debug_opaque_type);
2169 return debug_opaque_type;
2170 },
2101 .Array => {2171 .Array => {
2102 const debug_array_type = try o.builder.debugArrayType(2172 const debug_array_type = try o.builder.debugArrayType(
2103 .none, // Name2173 .none, // Name
2104 .none, // File2174 .none, // File
2105 .none, // Scope2175 .none, // Scope
2106 0, // Line2176 0, // Line
2107 try o.lowerDebugType(ty.childType(zcu), required_by_runtime),2177 try o.lowerDebugType(ty.childType(zcu)),
2108 ty.abiSize(pt) * 8,2178 ty.abiSize(pt) * 8,
2109 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,2179 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2110 try o.builder.debugTuple(&.{2180 try o.builder.debugTuple(&.{
...@@ -2126,9 +2196,10 @@ pub const Object = struct {...@@ -2126,9 +2196,10 @@ pub const Object = struct {
2126 const debug_elem_type = switch (elem_ty.zigTypeTag(zcu)) {2196 const debug_elem_type = switch (elem_ty.zigTypeTag(zcu)) {
2127 .Int => blk: {2197 .Int => blk: {
2128 const info = elem_ty.intInfo(zcu);2198 const info = elem_ty.intInfo(zcu);
2129 const vec_name = try o.allocTypeName(ty);2199 assert(info.bits != 0);
2130 defer gpa.free(vec_name);2200 const name = try o.allocTypeName(ty);
2131 const builder_name = try o.builder.metadataString(vec_name);2201 defer gpa.free(name);
2202 const builder_name = try o.builder.metadataString(name);
2132 break :blk switch (info.signedness) {2203 break :blk switch (info.signedness) {
2133 .signed => try o.builder.debugSignedType(builder_name, info.bits),2204 .signed => try o.builder.debugSignedType(builder_name, info.bits),
2134 .unsigned => try o.builder.debugUnsignedType(builder_name, info.bits),2205 .unsigned => try o.builder.debugUnsignedType(builder_name, info.bits),
...@@ -2138,7 +2209,7 @@ pub const Object = struct {...@@ -2138,7 +2209,7 @@ pub const Object = struct {
2138 try o.builder.metadataString("bool"),2209 try o.builder.metadataString("bool"),
2139 1,2210 1,
2140 ),2211 ),
2141 else => try o.lowerDebugType(ty.childType(zcu), required_by_runtime),2212 else => try o.lowerDebugType(ty.childType(zcu)),
2142 };2213 };
21432214
2144 const debug_vector_type = try o.builder.debugVectorType(2215 const debug_vector_type = try o.builder.debugVectorType(
...@@ -2163,7 +2234,6 @@ pub const Object = struct {...@@ -2163,7 +2234,6 @@ pub const Object = struct {
2163 .Optional => {2234 .Optional => {
2164 const name = try o.allocTypeName(ty);2235 const name = try o.allocTypeName(ty);
2165 defer gpa.free(name);2236 defer gpa.free(name);
2166
2167 const child_ty = ty.optionalChild(zcu);2237 const child_ty = ty.optionalChild(zcu);
2168 if (!child_ty.hasRuntimeBitsIgnoreComptime(pt)) {2238 if (!child_ty.hasRuntimeBitsIgnoreComptime(pt)) {
2169 const debug_bool_type = try o.builder.debugBoolType(2239 const debug_bool_type = try o.builder.debugBoolType(
...@@ -2180,7 +2250,7 @@ pub const Object = struct {...@@ -2180,7 +2250,7 @@ pub const Object = struct {
2180 try o.debug_type_map.put(gpa, ty, debug_fwd_ref);2250 try o.debug_type_map.put(gpa, ty, debug_fwd_ref);
21812251
2182 if (ty.optionalReprIsPayload(zcu)) {2252 if (ty.optionalReprIsPayload(zcu)) {
2183 const debug_optional_type = try o.lowerDebugType(child_ty, required_by_runtime);2253 const debug_optional_type = try o.lowerDebugType(child_ty);
21842254
2185 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_optional_type);2255 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_optional_type);
21862256
...@@ -2203,7 +2273,7 @@ pub const Object = struct {...@@ -2203,7 +2273,7 @@ pub const Object = struct {
2203 .none, // File2273 .none, // File
2204 debug_fwd_ref,2274 debug_fwd_ref,
2205 0, // Line2275 0, // Line
2206 try o.lowerDebugType(child_ty, required_by_runtime),2276 try o.lowerDebugType(child_ty),
2207 payload_size * 8,2277 payload_size * 8,
2208 (payload_align.toByteUnits() orelse 0) * 8,2278 (payload_align.toByteUnits() orelse 0) * 8,
2209 0, // Offset2279 0, // Offset
...@@ -2214,7 +2284,7 @@ pub const Object = struct {...@@ -2214,7 +2284,7 @@ pub const Object = struct {
2214 .none,2284 .none,
2215 debug_fwd_ref,2285 debug_fwd_ref,
2216 0,2286 0,
2217 try o.lowerDebugType(non_null_ty, required_by_runtime),2287 try o.lowerDebugType(non_null_ty),
2218 non_null_size * 8,2288 non_null_size * 8,
2219 (non_null_align.toByteUnits() orelse 0) * 8,2289 (non_null_align.toByteUnits() orelse 0) * 8,
2220 non_null_offset * 8,2290 non_null_offset * 8,
...@@ -2232,7 +2302,6 @@ pub const Object = struct {...@@ -2232,7 +2302,6 @@ pub const Object = struct {
2232 debug_data_type,2302 debug_data_type,
2233 debug_some_type,2303 debug_some_type,
2234 }),2304 }),
2235 isByRef(ty, pt),
2236 );2305 );
22372306
2238 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_optional_type);2307 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_optional_type);
...@@ -2247,7 +2316,7 @@ pub const Object = struct {...@@ -2247,7 +2316,7 @@ pub const Object = struct {
2247 const payload_ty = ty.errorUnionPayload(zcu);2316 const payload_ty = ty.errorUnionPayload(zcu);
2248 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {2317 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
2249 // TODO: Maybe remove?2318 // TODO: Maybe remove?
2250 const debug_error_union_type = try o.lowerDebugType(Type.anyerror, required_by_runtime);2319 const debug_error_union_type = try o.lowerDebugType(Type.anyerror);
2251 try o.debug_type_map.put(gpa, ty, debug_error_union_type);2320 try o.debug_type_map.put(gpa, ty, debug_error_union_type);
2252 return debug_error_union_type;2321 return debug_error_union_type;
2253 }2322 }
...@@ -2284,7 +2353,7 @@ pub const Object = struct {...@@ -2284,7 +2353,7 @@ pub const Object = struct {
2284 .none, // File2353 .none, // File
2285 debug_fwd_ref,2354 debug_fwd_ref,
2286 0, // Line2355 0, // Line
2287 try o.lowerDebugType(Type.anyerror, required_by_runtime),2356 try o.lowerDebugType(Type.anyerror),
2288 error_size * 8,2357 error_size * 8,
2289 (error_align.toByteUnits() orelse 0) * 8,2358 (error_align.toByteUnits() orelse 0) * 8,
2290 error_offset * 8,2359 error_offset * 8,
...@@ -2294,7 +2363,7 @@ pub const Object = struct {...@@ -2294,7 +2363,7 @@ pub const Object = struct {
2294 .none, // File2363 .none, // File
2295 debug_fwd_ref,2364 debug_fwd_ref,
2296 0, // Line2365 0, // Line
2297 try o.lowerDebugType(payload_ty, required_by_runtime),2366 try o.lowerDebugType(payload_ty),
2298 payload_size * 8,2367 payload_size * 8,
2299 (payload_align.toByteUnits() orelse 0) * 8,2368 (payload_align.toByteUnits() orelse 0) * 8,
2300 payload_offset * 8,2369 payload_offset * 8,
...@@ -2309,7 +2378,6 @@ pub const Object = struct {...@@ -2309,7 +2378,6 @@ pub const Object = struct {
2309 ty.abiSize(pt) * 8,2378 ty.abiSize(pt) * 8,
2310 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,2379 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2311 try o.builder.debugTuple(&fields),2380 try o.builder.debugTuple(&fields),
2312 isByRef(ty, pt),
2313 );2381 );
23142382
2315 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_error_union_type);2383 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_error_union_type);
...@@ -2325,483 +2393,383 @@ pub const Object = struct {...@@ -2325,483 +2393,383 @@ pub const Object = struct {
2325 try o.debug_type_map.put(gpa, ty, debug_error_set);2393 try o.debug_type_map.put(gpa, ty, debug_error_set);
2326 return debug_error_set;2394 return debug_error_set;
2327 },2395 },
2328 .Fn => {2396 .Struct => {
2329 const fn_info = zcu.typeToFunc(ty).?;2397 const name = try o.allocTypeName(ty);
23302398 defer gpa.free(name);
2331 var debug_param_types = std.ArrayList(Builder.Metadata).init(gpa);
2332 defer debug_param_types.deinit();
2333
2334 try debug_param_types.ensureUnusedCapacity(3 + fn_info.param_types.len);
2335
2336 // Return type goes first.
2337 if (Type.fromInterned(fn_info.return_type).hasRuntimeBitsIgnoreComptime(pt)) {
2338 const sret = firstParamSRet(fn_info, pt, target);
2339 const ret_ty = if (sret) Type.void else Type.fromInterned(fn_info.return_type);
2340 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ret_ty, required_by_runtime));
2341
2342 if (sret) {
2343 const ptr_ty = try pt.singleMutPtrType(Type.fromInterned(fn_info.return_type));
2344 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty, required_by_runtime));
2345 }
2346 } else {
2347 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(Type.void, required_by_runtime));
2348 }
2349
2350 if (Type.fromInterned(fn_info.return_type).isError(zcu) and
2351 zcu.comp.config.any_error_tracing)
2352 {
2353 const ptr_ty = try pt.singleMutPtrType(try o.getStackTraceType());
2354 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty, required_by_runtime));
2355 }
2356
2357 for (0..fn_info.param_types.len) |i| {
2358 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[i]);
2359 if (!param_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;
23602399
2361 if (isByRef(param_ty, pt)) {2400 if (zcu.typeToPackedStruct(ty)) |struct_type| {
2362 const ptr_ty = try pt.singleMutPtrType(param_ty);2401 const backing_int_ty = struct_type.backingIntTypeUnordered(ip);
2363 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty, required_by_runtime));2402 if (backing_int_ty != .none) {
2364 } else {2403 const info = Type.fromInterned(backing_int_ty).intInfo(zcu);
2365 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(param_ty, required_by_runtime));2404 const builder_name = try o.builder.metadataString(name);
2405 const debug_int_type = switch (info.signedness) {
2406 .signed => try o.builder.debugSignedType(builder_name, ty.abiSize(pt) * 8),
2407 .unsigned => try o.builder.debugUnsignedType(builder_name, ty.abiSize(pt) * 8),
2408 };
2409 try o.debug_type_map.put(gpa, ty, debug_int_type);
2410 return debug_int_type;
2366 }2411 }
2367 }2412 }
23682413
2369 const debug_function_type = try o.builder.debugSubroutineType(2414 switch (ip.indexToKey(ty.toIntern())) {
2370 try o.builder.debugTuple(debug_param_types.items),2415 .anon_struct_type => |tuple| {
2371 );2416 var fields: std.ArrayListUnmanaged(Builder.Metadata) = .{};
2417 defer fields.deinit(gpa);
2418
2419 try fields.ensureUnusedCapacity(gpa, tuple.types.len);
2420
2421 comptime assert(struct_layout_version == 2);
2422 var offset: u64 = 0;
2423
2424 const debug_fwd_ref = try o.builder.debugForwardReference();
2425
2426 for (tuple.types.get(ip), tuple.values.get(ip), 0..) |field_ty, field_val, i| {
2427 if (field_val != .none or !Type.fromInterned(field_ty).hasRuntimeBits(pt)) continue;
2428
2429 const field_size = Type.fromInterned(field_ty).abiSize(pt);
2430 const field_align = Type.fromInterned(field_ty).abiAlignment(pt);
2431 const field_offset = field_align.forward(offset);
2432 offset = field_offset + field_size;
2433
2434 const field_name = if (tuple.names.len != 0)
2435 tuple.names.get(ip)[i].toSlice(ip)
2436 else
2437 try std.fmt.allocPrintZ(gpa, "{d}", .{i});
2438 defer if (tuple.names.len == 0) gpa.free(field_name);
2439
2440 fields.appendAssumeCapacity(try o.builder.debugMemberType(
2441 try o.builder.metadataString(field_name),
2442 .none, // File
2443 debug_fwd_ref,
2444 0,
2445 try o.lowerDebugType(Type.fromInterned(field_ty)),
2446 field_size * 8,
2447 (field_align.toByteUnits() orelse 0) * 8,
2448 field_offset * 8,
2449 ));
2450 }
23722451
2373 try o.debug_type_map.put(gpa, ty, debug_function_type);2452 const debug_struct_type = try o.builder.debugStructType(
2374 return debug_function_type;2453 try o.builder.metadataString(name),
2375 },2454 .none, // File
2376 .ComptimeInt => unreachable,2455 o.debug_compile_unit, // Scope
2377 .ComptimeFloat => unreachable,2456 0, // Line
2378 .Type => unreachable,2457 .none, // Underlying type
2379 .Undefined => unreachable,2458 ty.abiSize(pt) * 8,
2380 .Null => unreachable,2459 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2381 .EnumLiteral => unreachable,2460 try o.builder.debugTuple(fields.items),
2461 );
23822462
2383 .Frame => @panic("TODO implement lowerDebugType for Frame types"),2463 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_struct_type);
2384 .AnyFrame => @panic("TODO implement lowerDebugType for AnyFrame types"),
2385 // These are the types that need a correct scope.
2386 .Enum, .Struct, .Union, .Opaque => {},
2387 }
2388 const fwd_ref = try o.builder.debugForwardReference();
2389 try o.debug_type_map.put(gpa, ty, fwd_ref);
2390 try o.debug_unresolved_namespace_scopes.put(gpa, ty, required_by_runtime);
23912464
2392 return fwd_ref;2465 try o.debug_type_map.put(gpa, ty, debug_struct_type);
2393 }2466 return debug_struct_type;
2467 },
2468 .struct_type => {
2469 if (!ip.loadStructType(ty.toIntern()).haveFieldTypes(ip)) {
2470 // This can happen if a struct type makes it all the way to
2471 // flush() without ever being instantiated or referenced (even
2472 // via pointer). The only reason we are hearing about it now is
2473 // that it is being used as a namespace to put other debug types
2474 // into. Therefore we can satisfy this by making an empty namespace,
2475 // rather than changing the frontend to unnecessarily resolve the
2476 // struct field types.
2477 const owner_decl_index = ty.getOwnerDecl(zcu);
2478 const debug_struct_type = try o.makeEmptyNamespaceDebugType(owner_decl_index);
2479 try o.debug_type_map.put(gpa, ty, debug_struct_type);
2480 return debug_struct_type;
2481 }
2482 },
2483 else => {},
2484 }
23942485
2395 fn genNamespaces(o: *Object) !void {2486 if (!ty.hasRuntimeBitsIgnoreComptime(pt)) {
2396 const gpa = o.gpa;2487 const owner_decl_index = ty.getOwnerDecl(zcu);
2397 const pt = o.pt;2488 const debug_struct_type = try o.makeEmptyNamespaceDebugType(owner_decl_index);
2398 const zcu = pt.zcu;2489 try o.debug_type_map.put(gpa, ty, debug_struct_type);
2399 const ip = &zcu.intern_pool;2490 return debug_struct_type;
2491 }
24002492
2401 var fields: std.ArrayListUnmanaged(Builder.Metadata) = .{};2493 const struct_type = zcu.typeToStruct(ty).?;
2402 defer fields.deinit(gpa);
24032494
2404 const unresolved = &o.debug_unresolved_namespace_scopes;2495 var fields: std.ArrayListUnmanaged(Builder.Metadata) = .{};
2405 var unresolved_i: usize = 0;2496 defer fields.deinit(gpa);
2406 while (unresolved_i < unresolved.count()) : (unresolved_i += 1) {
2407 const ty = unresolved.keys()[unresolved_i];
2408 const required_by_runtime = unresolved.values()[unresolved_i];
24092497
2410 const owner_decl_index = ty.getOwnerDeclOrNull(zcu);2498 try fields.ensureUnusedCapacity(gpa, struct_type.field_types.len);
2411 const owner_decl: ?*Zcu.Decl =
2412 if (owner_decl_index) |owner| ip.declPtr(owner) else null;
24132499
2414 const file = if (owner_decl) |owner|2500 const debug_fwd_ref = try o.builder.debugForwardReference();
2415 try o.getDebugFile(zcu.namespacePtr(owner.src_namespace).fileScope(zcu))
2416 else
2417 .none;
2418 const scope = if (owner_decl) |owner|
2419 try o.namespaceToDebugScope(owner.src_namespace)
2420 else
2421 o.debug_compile_unit;
2422 const line = if (owner_decl) |owner| owner.typeSrcLine(zcu) + 1 else 0;
24232501
2424 const name = if (owner_decl) |owner| owner.name.toSlice(ip) else try o.allocTypeName(ty);2502 // Set as forward reference while the type is lowered in case it references itself
2425 defer if (owner_decl == null) gpa.free(name);2503 try o.debug_type_map.put(gpa, ty, debug_fwd_ref);
24262504
2427 const fwd_ref = o.debug_type_map.get(ty).?;2505 comptime assert(struct_layout_version == 2);
2506 var it = struct_type.iterateRuntimeOrder(ip);
2507 while (it.next()) |field_index| {
2508 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]);
2509 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;
2510 const field_size = field_ty.abiSize(pt);
2511 const field_align = pt.structFieldAlignment(
2512 struct_type.fieldAlign(ip, field_index),
2513 field_ty,
2514 struct_type.layout,
2515 );
2516 const field_offset = ty.structFieldOffset(field_index, pt);
24282517
2429 fields.clearRetainingCapacity();2518 const field_name = struct_type.fieldName(ip, field_index).unwrap() orelse
2519 try ip.getOrPutStringFmt(gpa, pt.tid, "{d}", .{field_index}, .no_embedded_nulls);
24302520
2431 const ns = if (ty.getNamespace(zcu)) |n| n.unwrap() else null;2521 fields.appendAssumeCapacity(try o.builder.debugMemberType(
2432 if (ns) |ns_id| {2522 try o.builder.metadataString(field_name.toSlice(ip)),
2433 const namespace = ip.namespacePtr(ns_id);2523 .none, // File
2434 try fields.ensureUnusedCapacity(gpa, namespace.decls.keys().len);2524 debug_fwd_ref,
2525 0, // Line
2526 try o.lowerDebugType(field_ty),
2527 field_size * 8,
2528 (field_align.toByteUnits() orelse 0) * 8,
2529 field_offset * 8,
2530 ));
2531 }
24352532
2436 for (namespace.decls.keys()) |decl_id| {2533 const debug_struct_type = try o.builder.debugStructType(
2437 const decl = ip.declPtr(decl_id);2534 try o.builder.metadataString(name),
2438 const decl_name = decl.name.toSlice(ip);2535 .none, // File
2536 o.debug_compile_unit, // Scope
2537 0, // Line
2538 .none, // Underlying type
2539 ty.abiSize(pt) * 8,
2540 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2541 try o.builder.debugTuple(fields.items),
2542 );
24392543
2440 if (!decl.has_tv) continue;2544 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_struct_type);
2441 if (decl.kind != .named) continue;
2442 if (decl.analysis != .complete) continue;
24432545
2444 const decl_line = 0;2546 // Set to real type now that it has been lowered fully
2547 const map_ptr = o.debug_type_map.getPtr(ty) orelse unreachable;
2548 map_ptr.* = debug_struct_type;
24452549
2446 if (decl.val.typeOf(zcu).ip_index == .type_type) {2550 return debug_struct_type;
2447 const nested_type = decl.val.toType();2551 },
2448 // If this decl is the owner of the type, it will2552 .Union => {
2449 // already have been declared as a direct child and2553 const owner_decl_index = ty.getOwnerDecl(zcu);
2450 // will not need to be typedef'd.
2451 if (nested_type.getOwnerDeclOrNull(zcu)) |owner| {
2452 if (owner == decl_id) continue;
2453 }
24542554
2455 switch (nested_type.zigTypeTag(zcu)) {2555 const name = try o.allocTypeName(ty);
2456 // We still may want these for a Zig expression2556 defer gpa.free(name);
2457 // evaluator in debuggers, but for now they are
2458 // completely useless.
2459 .ComptimeInt, .ComptimeFloat, .Type, .Undefined, .Null, .EnumLiteral => continue,
2460 else => {},
2461 }
24622557
2463 fields.appendAssumeCapacity(try o.builder.debugTypedef(2558 const union_type = ip.loadUnionType(ty.toIntern());
2464 try o.builder.metadataString(decl_name),2559 if (!union_type.haveFieldTypes(ip) or
2465 try o.getDebugFile(namespace.fileScope(zcu)),2560 !ty.hasRuntimeBitsIgnoreComptime(pt) or
2466 fwd_ref,2561 !union_type.haveLayout(ip))
2467 decl_line,2562 {
2468 try o.lowerDebugType(nested_type, false),2563 const debug_union_type = try o.makeEmptyNamespaceDebugType(owner_decl_index);
2469 0, // Align2564 try o.debug_type_map.put(gpa, ty, debug_union_type);
2470 ));2565 return debug_union_type;
2471 }
2472 }2566 }
2473 }
24742567
2475 if (!required_by_runtime) {2568 const layout = pt.getUnionLayout(union_type);
2476 const res = try o.makeNamespaceDebugType(owner_decl_index.?, fields.items);
2477 o.builder.debugForwardReferenceSetType(fwd_ref, res);
2478 continue;
2479 }
2480
2481 const res = switch (ty.zigTypeTag(zcu)) {
2482 .Enum => res: {
2483 if (!ty.hasRuntimeBitsIgnoreComptime(pt)) {
2484 break :res try o.makeNamespaceDebugType(owner_decl_index.?, fields.items);
2485 }
2486
2487 const enum_type = ip.loadEnumType(ty.toIntern());
2488
2489 const enumerators = try gpa.alloc(Builder.Metadata, enum_type.names.len);
2490 defer gpa.free(enumerators);
24912569
2492 const int_ty = Type.fromInterned(enum_type.tag_ty);2570 const debug_fwd_ref = try o.builder.debugForwardReference();
2493 const int_info = ty.intInfo(zcu);
2494 assert(int_info.bits != 0);
2495
2496 for (enum_type.names.get(ip), 0..) |field_name_ip, i| {
2497 var bigint_space: Value.BigIntSpace = undefined;
2498 const bigint = if (enum_type.values.len != 0)
2499 Value.fromInterned(enum_type.values.get(ip)[i]).toBigInt(&bigint_space, pt)
2500 else
2501 std.math.big.int.Mutable.init(&bigint_space.limbs, i).toConst();
25022571
2503 enumerators[i] = try o.builder.debugEnumerator(2572 // Set as forward reference while the type is lowered in case it references itself
2504 try o.builder.metadataString(field_name_ip.toSlice(ip)),2573 try o.debug_type_map.put(gpa, ty, debug_fwd_ref);
2505 int_info.signedness == .unsigned,
2506 int_info.bits,
2507 bigint,
2508 );
2509 }
25102574
2511 const debug_enum_type = try o.builder.debugEnumerationType(2575 if (layout.payload_size == 0) {
2576 const debug_union_type = try o.builder.debugStructType(
2512 try o.builder.metadataString(name),2577 try o.builder.metadataString(name),
2513 file,2578 .none, // File
2514 scope,2579 o.debug_compile_unit, // Scope
2515 line,2580 0, // Line
2516 try o.lowerDebugType(int_ty, required_by_runtime),2581 .none, // Underlying type
2517 ty.abiSize(pt) * 8,2582 ty.abiSize(pt) * 8,
2518 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,2583 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2519 try o.builder.debugTuple(enumerators),2584 try o.builder.debugTuple(
2585 &.{try o.lowerDebugType(Type.fromInterned(union_type.enum_tag_ty))},
2586 ),
2520 );2587 );
25212588
2522 try o.debug_enums.append(gpa, debug_enum_type);2589 // Set to real type now that it has been lowered fully
2523 break :res debug_enum_type;2590 const map_ptr = o.debug_type_map.getPtr(ty) orelse unreachable;
2524 },2591 map_ptr.* = debug_union_type;
2525 .Opaque => res: {
2526 if (ty.toIntern() == .anyopaque_type) {
2527 break :res try o.builder.debugSignedType(
2528 try o.builder.metadataString("anyopaque"),
2529 0,
2530 );
2531 }
2532
2533 const debug_opaque_type = try o.builder.debugStructType(
2534 try o.builder.metadataString(name),
2535 file,
2536 scope,
2537 line,
2538 .none, // Underlying type
2539 0, // Size
2540 0, // Align
2541 .none, // Fields
2542 false, // ByRef
2543 );
2544 break :res debug_opaque_type;
2545 },
2546 .Struct => res: {
2547 if (zcu.typeToPackedStruct(ty)) |struct_type| {
2548 const backing_int_ty = struct_type.backingIntTypeUnordered(ip);
2549 if (backing_int_ty != .none) {
2550 const info = Type.fromInterned(backing_int_ty).intInfo(zcu);
2551 const builder_name = try o.builder.metadataString(name);
2552 const debug_int_type = switch (info.signedness) {
2553 .signed => try o.builder.debugSignedType(builder_name, ty.abiSize(pt) * 8),
2554 .unsigned => try o.builder.debugUnsignedType(builder_name, ty.abiSize(pt) * 8),
2555 };
2556 break :res debug_int_type;
2557 }
2558 }
25592592
2560 switch (ip.indexToKey(ty.toIntern())) {2593 return debug_union_type;
2561 .anon_struct_type => |tuple| {2594 }
2562 try fields.ensureUnusedCapacity(gpa, tuple.types.len);
2563
2564 comptime assert(struct_layout_version == 2);
2565 var offset: u64 = 0;
2566
2567 for (tuple.types.get(ip), tuple.values.get(ip), 0..) |field_ty, field_val, i| {
2568 if (field_val != .none or !Type.fromInterned(field_ty).hasRuntimeBits(pt)) continue;
2569
2570 const field_size = Type.fromInterned(field_ty).abiSize(pt);
2571 const field_align = Type.fromInterned(field_ty).abiAlignment(pt);
2572 const field_offset = field_align.forward(offset);
2573 offset = field_offset + field_size;
2574
2575 const field_name = if (tuple.names.len != 0)
2576 tuple.names.get(ip)[i].toSlice(ip)
2577 else
2578 try std.fmt.allocPrintZ(gpa, "{d}", .{i});
2579 defer if (tuple.names.len == 0) gpa.free(field_name);
2580
2581 fields.appendAssumeCapacity(try o.builder.debugMemberType(
2582 try o.builder.metadataString(field_name),
2583 .none, // File
2584 fwd_ref,
2585 0,
2586 try o.lowerDebugType(Type.fromInterned(field_ty), required_by_runtime),
2587 field_size * 8,
2588 (field_align.toByteUnits() orelse 0) * 8,
2589 field_offset * 8,
2590 ));
2591 }
25922595
2593 const debug_struct_type = try o.builder.debugStructType(2596 var fields: std.ArrayListUnmanaged(Builder.Metadata) = .{};
2594 try o.builder.metadataString(name),2597 defer fields.deinit(gpa);
2595 file,
2596 scope,
2597 0, // Line
2598 .none, // Underlying type
2599 ty.abiSize(pt) * 8,
2600 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2601 try o.builder.debugTuple(fields.items),
2602 isByRef(ty, pt),
2603 );
26042598
2605 break :res debug_struct_type;2599 try fields.ensureUnusedCapacity(gpa, union_type.loadTagType(ip).names.len);
2606 },
2607 else => {},
2608 }
26092600
2610 if (!ty.hasRuntimeBitsIgnoreComptime(pt)) {2601 const debug_union_fwd_ref = if (layout.tag_size == 0)
2611 break :res try o.makeNamespaceDebugType(owner_decl_index.?, fields.items);2602 debug_fwd_ref
2612 }2603 else
2613 const struct_type = zcu.typeToStruct(ty).?;2604 try o.builder.debugForwardReference();
26142605
2615 if (!struct_type.haveLayout(ip) or !struct_type.haveFieldTypes(ip)) {2606 const tag_type = union_type.loadTagType(ip);
2616 break :res try o.makeNamespaceDebugType(owner_decl_index.?, fields.items);
2617 }
26182607
2619 try fields.ensureUnusedCapacity(gpa, struct_type.field_types.len);2608 for (0..tag_type.names.len) |field_index| {
2609 const field_ty = union_type.field_types.get(ip)[field_index];
2610 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(pt)) continue;
26202611
2621 comptime assert(struct_layout_version == 2);2612 const field_size = Type.fromInterned(field_ty).abiSize(pt);
2622 var it = struct_type.iterateRuntimeOrder(ip);2613 const field_align: InternPool.Alignment = switch (union_type.flagsUnordered(ip).layout) {
2623 while (it.next()) |field_index| {2614 .@"packed" => .none,
2624 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]);2615 .auto, .@"extern" => pt.unionFieldNormalAlignment(union_type, @intCast(field_index)),
2625 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;2616 };
2626 const field_size = field_ty.abiSize(pt);
2627 const field_align = pt.structFieldAlignment(
2628 struct_type.fieldAlign(ip, field_index),
2629 field_ty,
2630 struct_type.layout,
2631 );
2632 const field_offset = ty.structFieldOffset(field_index, pt);
26332617
2634 const field_name = struct_type.fieldName(ip, field_index).unwrap() orelse2618 const field_name = tag_type.names.get(ip)[field_index];
2635 try ip.getOrPutStringFmt(gpa, pt.tid, "{d}", .{field_index}, .no_embedded_nulls);2619 fields.appendAssumeCapacity(try o.builder.debugMemberType(
2620 try o.builder.metadataString(field_name.toSlice(ip)),
2621 .none, // File
2622 debug_union_fwd_ref,
2623 0, // Line
2624 try o.lowerDebugType(Type.fromInterned(field_ty)),
2625 field_size * 8,
2626 (field_align.toByteUnits() orelse 0) * 8,
2627 0, // Offset
2628 ));
2629 }
26362630
2637 fields.appendAssumeCapacity(try o.builder.debugMemberType(2631 var union_name_buf: ?[:0]const u8 = null;
2638 try o.builder.metadataString(field_name.toSlice(ip)),2632 defer if (union_name_buf) |buf| gpa.free(buf);
2639 file,2633 const union_name = if (layout.tag_size == 0) name else name: {
2640 fwd_ref,2634 union_name_buf = try std.fmt.allocPrintZ(gpa, "{s}:Payload", .{name});
2641 0, // Line2635 break :name union_name_buf.?;
2642 try o.lowerDebugType(field_ty, required_by_runtime),2636 };
2643 field_size * 8,
2644 (field_align.toByteUnits() orelse 0) * 8,
2645 field_offset * 8,
2646 ));
2647 }
26482637
2649 const debug_struct_type = try o.builder.debugStructType(2638 const debug_union_type = try o.builder.debugUnionType(
2650 try o.builder.metadataString(name),2639 try o.builder.metadataString(union_name),
2651 file,2640 .none, // File
2652 scope,2641 o.debug_compile_unit, // Scope
2653 line,2642 0, // Line
2654 .none, // Underlying type2643 .none, // Underlying type
2655 ty.abiSize(pt) * 8,2644 ty.abiSize(pt) * 8,
2656 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,2645 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2657 try o.builder.debugTuple(fields.items),2646 try o.builder.debugTuple(fields.items),
2658 isByRef(ty, pt),2647 );
2659 );
26602648
2661 break :res debug_struct_type;2649 o.builder.debugForwardReferenceSetType(debug_union_fwd_ref, debug_union_type);
2662 },
2663 .Union => res: {
2664 const union_type = ip.loadUnionType(ty.toIntern());
2665 if (!union_type.haveFieldTypes(ip) or
2666 !ty.hasRuntimeBitsIgnoreComptime(pt) or
2667 !union_type.haveLayout(ip))
2668 {
2669 break :res try o.makeNamespaceDebugType(owner_decl_index.?, fields.items);
2670 }
26712650
2672 const layout = pt.getUnionLayout(union_type);2651 if (layout.tag_size == 0) {
2652 // Set to real type now that it has been lowered fully
2653 const map_ptr = o.debug_type_map.getPtr(ty) orelse unreachable;
2654 map_ptr.* = debug_union_type;
26732655
2674 if (layout.payload_size == 0) {2656 return debug_union_type;
2675 const debug_union_type = try o.builder.debugStructType(2657 }
2676 try o.builder.metadataString(name),
2677 file,
2678 scope,
2679 0, // Line
2680 .none, // Underlying type
2681 ty.abiSize(pt) * 8,
2682 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2683 try o.builder.debugTuple(
2684 &.{try o.lowerDebugType(Type.fromInterned(union_type.enum_tag_ty), required_by_runtime)},
2685 ),
2686 isByRef(ty, pt),
2687 );
26882658
2689 break :res debug_union_type;2659 var tag_offset: u64 = undefined;
2690 }2660 var payload_offset: u64 = undefined;
2661 if (layout.tag_align.compare(.gte, layout.payload_align)) {
2662 tag_offset = 0;
2663 payload_offset = layout.payload_align.forward(layout.tag_size);
2664 } else {
2665 payload_offset = 0;
2666 tag_offset = layout.tag_align.forward(layout.payload_size);
2667 }
26912668
2692 try fields.ensureUnusedCapacity(gpa, union_type.loadTagType(ip).names.len);2669 const debug_tag_type = try o.builder.debugMemberType(
2670 try o.builder.metadataString("tag"),
2671 .none, // File
2672 debug_fwd_ref,
2673 0, // Line
2674 try o.lowerDebugType(Type.fromInterned(union_type.enum_tag_ty)),
2675 layout.tag_size * 8,
2676 (layout.tag_align.toByteUnits() orelse 0) * 8,
2677 tag_offset * 8,
2678 );
26932679
2694 const debug_union_fwd_ref = if (layout.tag_size == 0)2680 const debug_payload_type = try o.builder.debugMemberType(
2695 fwd_ref2681 try o.builder.metadataString("payload"),
2696 else2682 .none, // File
2697 try o.builder.debugForwardReference();2683 debug_fwd_ref,
2684 0, // Line
2685 debug_union_type,
2686 layout.payload_size * 8,
2687 (layout.payload_align.toByteUnits() orelse 0) * 8,
2688 payload_offset * 8,
2689 );
26982690
2699 const tag_type = union_type.loadTagType(ip);2691 const full_fields: [2]Builder.Metadata =
2692 if (layout.tag_align.compare(.gte, layout.payload_align))
2693 .{ debug_tag_type, debug_payload_type }
2694 else
2695 .{ debug_payload_type, debug_tag_type };
27002696
2701 for (0..tag_type.names.len) |field_index| {2697 const debug_tagged_union_type = try o.builder.debugStructType(
2702 const field_ty = union_type.field_types.get(ip)[field_index];2698 try o.builder.metadataString(name),
2703 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(pt)) continue;2699 .none, // File
2700 o.debug_compile_unit, // Scope
2701 0, // Line
2702 .none, // Underlying type
2703 ty.abiSize(pt) * 8,
2704 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2705 try o.builder.debugTuple(&full_fields),
2706 );
27042707
2705 const field_size = Type.fromInterned(field_ty).abiSize(pt);2708 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_tagged_union_type);
2706 const field_align: InternPool.Alignment = switch (union_type.flagsUnordered(ip).layout) {
2707 .@"packed" => .none,
2708 .auto, .@"extern" => pt.unionFieldNormalAlignment(union_type, @intCast(field_index)),
2709 };
27102709
2711 const field_name = tag_type.names.get(ip)[field_index];2710 // Set to real type now that it has been lowered fully
2712 fields.appendAssumeCapacity(try o.builder.debugMemberType(2711 const map_ptr = o.debug_type_map.getPtr(ty) orelse unreachable;
2713 try o.builder.metadataString(field_name.toSlice(ip)),2712 map_ptr.* = debug_tagged_union_type;
2714 file,
2715 debug_union_fwd_ref,
2716 0, // Line
2717 try o.lowerDebugType(Type.fromInterned(field_ty), required_by_runtime),
2718 field_size * 8,
2719 (field_align.toByteUnits() orelse 0) * 8,
2720 0, // Offset
2721 ));
2722 }
27232713
2724 var union_name_buf: ?[:0]const u8 = null;2714 return debug_tagged_union_type;
2725 defer if (union_name_buf) |buf| gpa.free(buf);2715 },
2726 const union_name = if (layout.tag_size == 0) name else name: {2716 .Fn => {
2727 union_name_buf = try std.fmt.allocPrintZ(gpa, "{s}:Payload", .{name});2717 const fn_info = zcu.typeToFunc(ty).?;
2728 break :name union_name_buf.?;
2729 };
27302718
2731 const debug_union_type = try o.builder.debugUnionType(2719 var debug_param_types = std.ArrayList(Builder.Metadata).init(gpa);
2732 try o.builder.metadataString(union_name),2720 defer debug_param_types.deinit();
2733 file,
2734 scope,
2735 line,
2736 .none, // Underlying type
2737 ty.abiSize(pt) * 8,
2738 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2739 try o.builder.debugTuple(fields.items),
2740 isByRef(ty, pt),
2741 );
27422721
2743 if (layout.tag_size == 0) {2722 try debug_param_types.ensureUnusedCapacity(3 + fn_info.param_types.len);
2744 break :res debug_union_type;
2745 }
27462723
2747 o.builder.debugForwardReferenceSetType(debug_union_fwd_ref, debug_union_type);2724 // Return type goes first.
2725 if (Type.fromInterned(fn_info.return_type).hasRuntimeBitsIgnoreComptime(pt)) {
2726 const sret = firstParamSRet(fn_info, pt, target);
2727 const ret_ty = if (sret) Type.void else Type.fromInterned(fn_info.return_type);
2728 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ret_ty));
27482729
2749 var tag_offset: u64 = undefined;2730 if (sret) {
2750 var payload_offset: u64 = undefined;2731 const ptr_ty = try pt.singleMutPtrType(Type.fromInterned(fn_info.return_type));
2751 if (layout.tag_align.compare(.gte, layout.payload_align)) {2732 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty));
2752 tag_offset = 0;
2753 payload_offset = layout.payload_align.forward(layout.tag_size);
2754 } else {
2755 payload_offset = 0;
2756 tag_offset = layout.tag_align.forward(layout.payload_size);
2757 }2733 }
2734 } else {
2735 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(Type.void));
2736 }
27582737
2759 const debug_tag_type = try o.builder.debugMemberType(2738 if (Type.fromInterned(fn_info.return_type).isError(zcu) and
2760 try o.builder.metadataString("tag"),2739 zcu.comp.config.any_error_tracing)
2761 file, // File2740 {
2762 fwd_ref,2741 const ptr_ty = try pt.singleMutPtrType(try o.getStackTraceType());
2763 0, // Line2742 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty));
2764 try o.lowerDebugType(Type.fromInterned(union_type.enum_tag_ty), required_by_runtime),2743 }
2765 layout.tag_size * 8,
2766 (layout.tag_align.toByteUnits() orelse 0) * 8,
2767 tag_offset * 8,
2768 );
27692744
2770 const debug_payload_type = try o.builder.debugMemberType(2745 for (0..fn_info.param_types.len) |i| {
2771 try o.builder.metadataString("payload"),2746 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[i]);
2772 file,2747 if (!param_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;
2773 fwd_ref,
2774 0, // Line
2775 debug_union_type,
2776 layout.payload_size * 8,
2777 (layout.payload_align.toByteUnits() orelse 0) * 8,
2778 payload_offset * 8,
2779 );
27802748
2781 const full_fields: [2]Builder.Metadata =2749 if (isByRef(param_ty, pt)) {
2782 if (layout.tag_align.compare(.gte, layout.payload_align))2750 const ptr_ty = try pt.singleMutPtrType(param_ty);
2783 .{ debug_tag_type, debug_payload_type }2751 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty));
2784 else2752 } else {
2785 .{ debug_payload_type, debug_tag_type };2753 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(param_ty));
2754 }
2755 }
27862756
2787 const debug_tagged_union_type = try o.builder.debugStructType(2757 const debug_function_type = try o.builder.debugSubroutineType(
2788 try o.builder.metadataString(name),2758 try o.builder.debugTuple(debug_param_types.items),
2789 file, // File2759 );
2790 scope,
2791 line,
2792 .none, // Underlying type
2793 ty.abiSize(pt) * 8,
2794 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2795 try o.builder.debugTuple(&full_fields),
2796 isByRef(ty, pt),
2797 );
27982760
2799 break :res debug_tagged_union_type;2761 try o.debug_type_map.put(gpa, ty, debug_function_type);
2800 },2762 return debug_function_type;
2801 else => unreachable, // Handled above.2763 },
2802 };2764 .ComptimeInt => unreachable,
2765 .ComptimeFloat => unreachable,
2766 .Type => unreachable,
2767 .Undefined => unreachable,
2768 .Null => unreachable,
2769 .EnumLiteral => unreachable,
28032770
2804 o.builder.debugForwardReferenceSetType(fwd_ref, res);2771 .Frame => @panic("TODO implement lowerDebugType for Frame types"),
2772 .AnyFrame => @panic("TODO implement lowerDebugType for AnyFrame types"),
2805 }2773 }
2806 }2774 }
28072775
...@@ -2811,10 +2779,14 @@ pub const Object = struct {...@@ -2811,10 +2779,14 @@ pub const Object = struct {
2811 const file_scope = namespace.fileScope(zcu);2779 const file_scope = namespace.fileScope(zcu);
2812 if (namespace.parent == .none) return try o.getDebugFile(file_scope);2780 if (namespace.parent == .none) return try o.getDebugFile(file_scope);
28132781
2814 return o.lowerDebugType(zcu.declPtr(namespace.decl_index).val.toType(), false);2782 const gop = try o.debug_unresolved_namespace_scopes.getOrPut(o.gpa, namespace_index);
2783
2784 if (!gop.found_existing) gop.value_ptr.* = try o.builder.debugForwardReference();
2785
2786 return gop.value_ptr.*;
2815 }2787 }
28162788
2817 fn makeNamespaceDebugType(o: *Object, decl_index: InternPool.DeclIndex, fields: []const Builder.Metadata) !Builder.Metadata {2789 fn makeEmptyNamespaceDebugType(o: *Object, decl_index: InternPool.DeclIndex) !Builder.Metadata {
2818 const zcu = o.pt.zcu;2790 const zcu = o.pt.zcu;
2819 const decl = zcu.declPtr(decl_index);2791 const decl = zcu.declPtr(decl_index);
2820 const file_scope = zcu.namespacePtr(decl.src_namespace).fileScope(zcu);2792 const file_scope = zcu.namespacePtr(decl.src_namespace).fileScope(zcu);
...@@ -2826,8 +2798,7 @@ pub const Object = struct {...@@ -2826,8 +2798,7 @@ pub const Object = struct {
2826 .none,2798 .none,
2827 0,2799 0,
2828 0,2800 0,
2829 if (fields.len == 0) .none else try o.builder.debugTuple(fields),2801 .none,
2830 false, // is_byref
2831 );2802 );
2832 }2803 }
28332804
...@@ -4741,33 +4712,16 @@ pub const DeclGen = struct {...@@ -4741,33 +4712,16 @@ pub const DeclGen = struct {
4741 if (!owner_mod.strip) {4712 if (!owner_mod.strip) {
4742 const debug_file = try o.getDebugFile(file_scope);4713 const debug_file = try o.getDebugFile(file_scope);
47434714
4744 const linkage_name = try o.builder.metadataStringFromStrtabString(variable_index.name(&o.builder));
4745 const is_internal_linkage = !decl.isExtern(zcu);
4746
4747 const ty = try o.lowerDebugType(decl.typeOf(zcu), true);
4748 const debug_global_var = try o.builder.debugGlobalVar(4715 const debug_global_var = try o.builder.debugGlobalVar(
4749 linkage_name,4716 try o.builder.metadataString(decl.name.toSlice(ip)), // Name
4750 linkage_name,4717 try o.builder.metadataStringFromStrtabString(variable_index.name(&o.builder)), // Linkage name
4751 debug_file,4718 debug_file, // File
4752 debug_file,4719 debug_file, // Scope
4753 line_number,4720 line_number,
4754 ty,4721 try o.lowerDebugType(decl.typeOf(zcu)),
4755 variable_index,4722 variable_index,
4756 is_internal_linkage,4723 .{ .local = !decl.isExtern(zcu) },
4757 );4724 );
4758 if (is_internal_linkage) {
4759 const name = try o.builder.metadataString(decl.name.toSlice(ip));
4760 const debug_scope = try o.namespaceToDebugScope(decl.src_namespace);
4761
4762 const import = try o.builder.debugImportDeclaration(
4763 name,
4764 debug_file,
4765 debug_scope,
4766 line_number,
4767 debug_global_var,
4768 );
4769 try o.debug_imports.append(o.gpa, import);
4770 }
47714725
4772 const debug_expression = try o.builder.debugExpression(&.{});4726 const debug_expression = try o.builder.debugExpression(&.{});
47734727
...@@ -5218,12 +5172,11 @@ pub const FuncGen = struct {...@@ -5218,12 +5172,11 @@ pub const FuncGen = struct {
52185172
5219 self.scope = try o.builder.debugSubprogram(5173 self.scope = try o.builder.debugSubprogram(
5220 self.file,5174 self.file,
5221 self.file, // TODO Get the correct scope into here—self.scope is the function's *inner* scope.
5222 try o.builder.metadataString(decl.name.toSlice(&zcu.intern_pool)),5175 try o.builder.metadataString(decl.name.toSlice(&zcu.intern_pool)),
5223 try o.builder.metadataString(decl.fqn.toSlice(&zcu.intern_pool)),5176 try o.builder.metadataString(decl.fqn.toSlice(&zcu.intern_pool)),
5224 line_number,5177 line_number,
5225 line_number + func.lbrace_line,5178 line_number + func.lbrace_line,
5226 try o.lowerDebugType(fn_ty, true),5179 try o.lowerDebugType(fn_ty),
5227 .{5180 .{
5228 .di_flags = .{ .StaticMember = true },5181 .di_flags = .{ .StaticMember = true },
5229 .sp_flags = .{5182 .sp_flags = .{
...@@ -6773,7 +6726,7 @@ pub const FuncGen = struct {...@@ -6773,7 +6726,7 @@ pub const FuncGen = struct {
6773 self.file,6726 self.file,
6774 self.scope,6727 self.scope,
6775 self.prev_dbg_line,6728 self.prev_dbg_line,
6776 try o.lowerDebugType(ptr_ty.childType(mod), true),6729 try o.lowerDebugType(ptr_ty.childType(mod)),
6777 );6730 );
67786731
6779 _ = try self.wip.callIntrinsic(6732 _ = try self.wip.callIntrinsic(
...@@ -6806,7 +6759,7 @@ pub const FuncGen = struct {...@@ -6806,7 +6759,7 @@ pub const FuncGen = struct {
6806 self.file,6759 self.file,
6807 self.scope,6760 self.scope,
6808 self.prev_dbg_line,6761 self.prev_dbg_line,
6809 try o.lowerDebugType(operand_ty, true),6762 try o.lowerDebugType(operand_ty),
6810 );6763 );
68116764
6812 const pt = o.pt;6765 const pt = o.pt;
...@@ -8920,7 +8873,7 @@ pub const FuncGen = struct {...@@ -8920,7 +8873,7 @@ pub const FuncGen = struct {
8920 self.file,8873 self.file,
8921 self.scope,8874 self.scope,
8922 lbrace_line,8875 lbrace_line,
8923 try o.lowerDebugType(inst_ty, true),8876 try o.lowerDebugType(inst_ty),
8924 @intCast(self.arg_index),8877 @intCast(self.arg_index),
8925 );8878 );
89268879
src/codegen/llvm/Builder.zig+22-150
...@@ -7651,8 +7651,6 @@ pub const Metadata = enum(u32) {...@@ -7651,8 +7651,6 @@ pub const Metadata = enum(u32) {
7651 composite_vector_type,7651 composite_vector_type,
7652 derived_pointer_type,7652 derived_pointer_type,
7653 derived_member_type,7653 derived_member_type,
7654 derived_typedef,
7655 imported_declaration,
7656 subroutine_type,7654 subroutine_type,
7657 enumerator_unsigned,7655 enumerator_unsigned,
7658 enumerator_signed_positive,7656 enumerator_signed_positive,
...@@ -7698,8 +7696,6 @@ pub const Metadata = enum(u32) {...@@ -7698,8 +7696,6 @@ pub const Metadata = enum(u32) {
7698 .composite_vector_type,7696 .composite_vector_type,
7699 .derived_pointer_type,7697 .derived_pointer_type,
7700 .derived_member_type,7698 .derived_member_type,
7701 .derived_typedef,
7702 .imported_declaration,
7703 .subroutine_type,7699 .subroutine_type,
7704 .enumerator_unsigned,7700 .enumerator_unsigned,
7705 .enumerator_signed_positive,7701 .enumerator_signed_positive,
...@@ -7816,7 +7812,6 @@ pub const Metadata = enum(u32) {...@@ -7816,7 +7812,6 @@ pub const Metadata = enum(u32) {
7816 producer: MetadataString,7812 producer: MetadataString,
7817 enums: Metadata,7813 enums: Metadata,
7818 globals: Metadata,7814 globals: Metadata,
7819 imports: Metadata,
7820 };7815 };
78217816
7822 pub const Subprogram = struct {7817 pub const Subprogram = struct {
...@@ -7865,7 +7860,6 @@ pub const Metadata = enum(u32) {...@@ -7865,7 +7860,6 @@ pub const Metadata = enum(u32) {
7865 }7860 }
7866 };7861 };
78677862
7868 scope: Metadata,
7869 file: Metadata,7863 file: Metadata,
7870 name: MetadataString,7864 name: MetadataString,
7871 linkage_name: MetadataString,7865 linkage_name: MetadataString,
...@@ -7911,10 +7905,6 @@ pub const Metadata = enum(u32) {...@@ -7911,10 +7905,6 @@ pub const Metadata = enum(u32) {
7911 align_in_bits_lo: u32,7905 align_in_bits_lo: u32,
7912 align_in_bits_hi: u32,7906 align_in_bits_hi: u32,
7913 fields_tuple: Metadata,7907 fields_tuple: Metadata,
7914 flags: packed struct(u32) {
7915 is_byref: bool,
7916 pad: u31 = 0,
7917 },
79187908
7919 pub fn bitSize(self: CompositeType) u64 {7909 pub fn bitSize(self: CompositeType) u64 {
7920 return @as(u64, self.size_in_bits_hi) << 32 | self.size_in_bits_lo;7910 return @as(u64, self.size_in_bits_hi) << 32 | self.size_in_bits_lo;
...@@ -7948,14 +7938,6 @@ pub const Metadata = enum(u32) {...@@ -7948,14 +7938,6 @@ pub const Metadata = enum(u32) {
7948 }7938 }
7949 };7939 };
79507940
7951 pub const ImportedEntity = struct {
7952 name: MetadataString,
7953 file: Metadata,
7954 scope: Metadata,
7955 line: u32,
7956 entity: Metadata,
7957 };
7958
7959 pub const SubroutineType = struct {7941 pub const SubroutineType = struct {
7960 types_tuple: Metadata,7942 types_tuple: Metadata,
7961 };7943 };
...@@ -8008,6 +7990,10 @@ pub const Metadata = enum(u32) {...@@ -8008,6 +7990,10 @@ pub const Metadata = enum(u32) {
8008 };7990 };
80097991
8010 pub const GlobalVar = struct {7992 pub const GlobalVar = struct {
7993 pub const Options = struct {
7994 local: bool,
7995 };
7996
8011 name: MetadataString,7997 name: MetadataString,
8012 linkage_name: MetadataString,7998 linkage_name: MetadataString,
8013 file: Metadata,7999 file: Metadata,
...@@ -8238,7 +8224,6 @@ pub const Metadata = enum(u32) {...@@ -8238,7 +8224,6 @@ pub const Metadata = enum(u32) {
8238 DIBasicType,8224 DIBasicType,
8239 DICompositeType,8225 DICompositeType,
8240 DIDerivedType,8226 DIDerivedType,
8241 DIImportedEntity,
8242 DISubroutineType,8227 DISubroutineType,
8243 DIEnumerator,8228 DIEnumerator,
8244 DISubrange,8229 DISubrange,
...@@ -9976,7 +9961,7 @@ pub fn printUnbuffered(...@@ -9976,7 +9961,7 @@ pub fn printUnbuffered(
9976 .enums = extra.enums,9961 .enums = extra.enums,
9977 .retainedTypes = null,9962 .retainedTypes = null,
9978 .globals = extra.globals,9963 .globals = extra.globals,
9979 .imports = extra.imports,9964 .imports = null,
9980 .macros = null,9965 .macros = null,
9981 .dwoId = null,9966 .dwoId = null,
9982 .splitDebugInlining = false,9967 .splitDebugInlining = false,
...@@ -10000,7 +9985,7 @@ pub fn printUnbuffered(...@@ -10000,7 +9985,7 @@ pub fn printUnbuffered(
10000 try metadata_formatter.specialized(.@"distinct !", .DISubprogram, .{9985 try metadata_formatter.specialized(.@"distinct !", .DISubprogram, .{
10001 .name = extra.name,9986 .name = extra.name,
10002 .linkageName = extra.linkage_name,9987 .linkageName = extra.linkage_name,
10003 .scope = extra.scope,9988 .scope = extra.file,
10004 .file = extra.file,9989 .file = extra.file,
10005 .line = extra.line,9990 .line = extra.line,
10006 .type = extra.ty,9991 .type = extra.ty,
...@@ -10094,8 +10079,8 @@ pub fn printUnbuffered(...@@ -10094,8 +10079,8 @@ pub fn printUnbuffered(
10094 else => extra.name,10079 else => extra.name,
10095 },10080 },
10096 .scope = extra.scope,10081 .scope = extra.scope,
10097 .file = extra.file,10082 .file = null,
10098 .line = extra.line,10083 .line = null,
10099 .baseType = extra.underlying_type,10084 .baseType = extra.underlying_type,
10100 .size = extra.bitSize(),10085 .size = extra.bitSize(),
10101 .@"align" = extra.bitAlign(),10086 .@"align" = extra.bitAlign(),
...@@ -10116,18 +10101,15 @@ pub fn printUnbuffered(...@@ -10116,18 +10101,15 @@ pub fn printUnbuffered(
10116 },10101 },
10117 .derived_pointer_type,10102 .derived_pointer_type,
10118 .derived_member_type,10103 .derived_member_type,
10119 .derived_typedef,
10120 => |kind| {10104 => |kind| {
10121 const extra = self.metadataExtraData(Metadata.DerivedType, metadata_item.data);10105 const extra = self.metadataExtraData(Metadata.DerivedType, metadata_item.data);
10122 try metadata_formatter.specialized(.@"!", .DIDerivedType, .{10106 try metadata_formatter.specialized(.@"!", .DIDerivedType, .{
10123 .tag = @as(enum {10107 .tag = @as(enum {
10124 DW_TAG_pointer_type,10108 DW_TAG_pointer_type,
10125 DW_TAG_member,10109 DW_TAG_member,
10126 DW_TAG_typedef,
10127 }, switch (kind) {10110 }, switch (kind) {
10128 .derived_pointer_type => .DW_TAG_pointer_type,10111 .derived_pointer_type => .DW_TAG_pointer_type,
10129 .derived_member_type => .DW_TAG_member,10112 .derived_member_type => .DW_TAG_member,
10130 .derived_typedef => .DW_TAG_typedef,
10131 else => unreachable,10113 else => unreachable,
10132 }),10114 }),
10133 .name = switch (extra.name) {10115 .name = switch (extra.name) {
...@@ -10150,22 +10132,6 @@ pub fn printUnbuffered(...@@ -10150,22 +10132,6 @@ pub fn printUnbuffered(
10150 .annotations = null,10132 .annotations = null,
10151 }, writer);10133 }, writer);
10152 },10134 },
10153 .imported_declaration => {
10154 const extra = self.metadataExtraData(Metadata.ImportedEntity, metadata_item.data);
10155
10156 try metadata_formatter.specialized(.@"!", .DIImportedEntity, .{
10157 .tag = .DW_TAG_imported_declaration,
10158 .scope = extra.scope,
10159 .entity = extra.entity,
10160 .file = extra.file,
10161 .line = extra.line,
10162 .name = switch (extra.name) {
10163 .none => null,
10164 else => extra.name,
10165 },
10166 .elements = null,
10167 }, writer);
10168 },
10169 .subroutine_type => {10135 .subroutine_type => {
10170 const extra = self.metadataExtraData(Metadata.SubroutineType, metadata_item.data);10136 const extra = self.metadataExtraData(Metadata.SubroutineType, metadata_item.data);
10171 try metadata_formatter.specialized(.@"!", .DISubroutineType, .{10137 try metadata_formatter.specialized(.@"!", .DISubroutineType, .{
...@@ -10289,7 +10255,11 @@ pub fn printUnbuffered(...@@ -10289,7 +10255,11 @@ pub fn printUnbuffered(
10289 .file = extra.file,10255 .file = extra.file,
10290 .line = extra.line,10256 .line = extra.line,
10291 .type = extra.ty,10257 .type = extra.ty,
10292 .isLocal = kind != .global_var,10258 .isLocal = switch (kind) {
10259 .global_var => false,
10260 .@"global_var local" => true,
10261 else => unreachable,
10262 },
10293 .isDefinition = true,10263 .isDefinition = true,
10294 .declaration = null,10264 .declaration = null,
10295 .templateParams = null,10265 .templateParams = null,
...@@ -11642,17 +11612,7 @@ fn addMetadataExtraAssumeCapacity(self: *Builder, extra: anytype) Metadata.Item....@@ -11642,17 +11612,7 @@ fn addMetadataExtraAssumeCapacity(self: *Builder, extra: anytype) Metadata.Item.
11642 u32 => value,11612 u32 => value,
11643 MetadataString, Metadata, Variable.Index, Value => @intFromEnum(value),11613 MetadataString, Metadata, Variable.Index, Value => @intFromEnum(value),
11644 Metadata.DIFlags => @bitCast(value),11614 Metadata.DIFlags => @bitCast(value),
11645 else => blk: {11615 else => @compileError("bad field type: " ++ @typeName(field.type)),
11646 switch (@typeInfo(field.type)) {
11647 .Struct => |s| {
11648 if (s.backing_integer == u32)
11649 break :blk @bitCast(value);
11650 @compileLog(s.layout, s.backing_integer);
11651 },
11652 else => {},
11653 }
11654 @compileError("bad field type: " ++ @typeName(field.type));
11655 },
11656 });11616 });
11657 }11617 }
11658 return result;11618 return result;
...@@ -11691,7 +11651,7 @@ fn metadataExtraDataTrail(...@@ -11691,7 +11651,7 @@ fn metadataExtraDataTrail(
11691 u32 => value,11651 u32 => value,
11692 MetadataString, Metadata, Variable.Index, Value => @enumFromInt(value),11652 MetadataString, Metadata, Variable.Index, Value => @enumFromInt(value),
11693 Metadata.DIFlags => @bitCast(value),11653 Metadata.DIFlags => @bitCast(value),
11694 else => @bitCast(value),11654 else => @compileError("bad field type: " ++ @typeName(field.type)),
11695 };11655 };
11696 return .{11656 return .{
11697 .data = result,11657 .data = result,
...@@ -11780,17 +11740,15 @@ pub fn debugCompileUnit(...@@ -11780,17 +11740,15 @@ pub fn debugCompileUnit(
11780 producer: MetadataString,11740 producer: MetadataString,
11781 enums: Metadata,11741 enums: Metadata,
11782 globals: Metadata,11742 globals: Metadata,
11783 imports: Metadata,
11784 options: Metadata.CompileUnit.Options,11743 options: Metadata.CompileUnit.Options,
11785) Allocator.Error!Metadata {11744) Allocator.Error!Metadata {
11786 try self.ensureUnusedMetadataCapacity(1, Metadata.CompileUnit, 0);11745 try self.ensureUnusedMetadataCapacity(1, Metadata.CompileUnit, 0);
11787 return self.debugCompileUnitAssumeCapacity(file, producer, enums, globals, imports, options);11746 return self.debugCompileUnitAssumeCapacity(file, producer, enums, globals, options);
11788}11747}
1178911748
11790pub fn debugSubprogram(11749pub fn debugSubprogram(
11791 self: *Builder,11750 self: *Builder,
11792 file: Metadata,11751 file: Metadata,
11793 scope: Metadata,
11794 name: MetadataString,11752 name: MetadataString,
11795 linkage_name: MetadataString,11753 linkage_name: MetadataString,
11796 line: u32,11754 line: u32,
...@@ -11802,7 +11760,6 @@ pub fn debugSubprogram(...@@ -11802,7 +11760,6 @@ pub fn debugSubprogram(
11802 try self.ensureUnusedMetadataCapacity(1, Metadata.Subprogram, 0);11760 try self.ensureUnusedMetadataCapacity(1, Metadata.Subprogram, 0);
11803 return self.debugSubprogramAssumeCapacity(11761 return self.debugSubprogramAssumeCapacity(
11804 file,11762 file,
11805 scope,
11806 name,11763 name,
11807 linkage_name,11764 linkage_name,
11808 line,11765 line,
...@@ -11858,7 +11815,6 @@ pub fn debugStructType(...@@ -11858,7 +11815,6 @@ pub fn debugStructType(
11858 size_in_bits: u64,11815 size_in_bits: u64,
11859 align_in_bits: u64,11816 align_in_bits: u64,
11860 fields_tuple: Metadata,11817 fields_tuple: Metadata,
11861 is_byref: bool,
11862) Allocator.Error!Metadata {11818) Allocator.Error!Metadata {
11863 try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0);11819 try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0);
11864 return self.debugStructTypeAssumeCapacity(11820 return self.debugStructTypeAssumeCapacity(
...@@ -11870,7 +11826,6 @@ pub fn debugStructType(...@@ -11870,7 +11826,6 @@ pub fn debugStructType(
11870 size_in_bits,11826 size_in_bits,
11871 align_in_bits,11827 align_in_bits,
11872 fields_tuple,11828 fields_tuple,
11873 is_byref,
11874 );11829 );
11875}11830}
1187611831
...@@ -11884,7 +11839,6 @@ pub fn debugUnionType(...@@ -11884,7 +11839,6 @@ pub fn debugUnionType(
11884 size_in_bits: u64,11839 size_in_bits: u64,
11885 align_in_bits: u64,11840 align_in_bits: u64,
11886 fields_tuple: Metadata,11841 fields_tuple: Metadata,
11887 is_byref: bool,
11888) Allocator.Error!Metadata {11842) Allocator.Error!Metadata {
11889 try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0);11843 try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0);
11890 return self.debugUnionTypeAssumeCapacity(11844 return self.debugUnionTypeAssumeCapacity(
...@@ -11896,7 +11850,6 @@ pub fn debugUnionType(...@@ -11896,7 +11850,6 @@ pub fn debugUnionType(
11896 size_in_bits,11850 size_in_bits,
11897 align_in_bits,11851 align_in_bits,
11898 fields_tuple,11852 fields_tuple,
11899 is_byref,
11900 );11853 );
11901}11854}
1190211855
...@@ -12020,53 +11973,6 @@ pub fn debugMemberType(...@@ -12020,53 +11973,6 @@ pub fn debugMemberType(
12020 );11973 );
12021}11974}
1202211975
12023pub fn debugTypedef(
12024 self: *Builder,
12025 name: MetadataString,
12026 file: Metadata,
12027 scope: Metadata,
12028 line: u32,
12029 underlying_type: Metadata,
12030 align_in_bits: u64,
12031) Allocator.Error!Metadata {
12032 try self.ensureUnusedMetadataCapacity(1, Metadata.DerivedType, 0);
12033
12034 assert(!self.strip);
12035 return self.metadataSimpleAssumeCapacity(.derived_typedef, Metadata.DerivedType{
12036 .name = name,
12037 .file = file,
12038 .scope = scope,
12039 .line = line,
12040 .underlying_type = underlying_type,
12041 .size_in_bits_lo = 0,
12042 .size_in_bits_hi = 0,
12043 .align_in_bits_lo = @truncate(align_in_bits),
12044 .align_in_bits_hi = @truncate(align_in_bits >> 32),
12045 .offset_in_bits_lo = 0,
12046 .offset_in_bits_hi = 0,
12047 });
12048}
12049
12050pub fn debugImportDeclaration(
12051 self: *Builder,
12052 name: MetadataString,
12053 file: Metadata,
12054 scope: Metadata,
12055 line: u32,
12056 entity: Metadata,
12057) Allocator.Error!Metadata {
12058 try self.ensureUnusedMetadataCapacity(1, Metadata.ImportedEntity, 0);
12059
12060 assert(!self.strip);
12061 return self.metadataSimpleAssumeCapacity(.imported_declaration, Metadata.ImportedEntity{
12062 .name = name,
12063 .file = file,
12064 .scope = scope,
12065 .line = line,
12066 .entity = entity,
12067 });
12068}
12069
12070pub fn debugSubroutineType(11976pub fn debugSubroutineType(
12071 self: *Builder,11977 self: *Builder,
12072 types_tuple: Metadata,11978 types_tuple: Metadata,
...@@ -12157,7 +12063,7 @@ pub fn debugGlobalVar(...@@ -12157,7 +12063,7 @@ pub fn debugGlobalVar(
12157 line: u32,12063 line: u32,
12158 ty: Metadata,12064 ty: Metadata,
12159 variable: Variable.Index,12065 variable: Variable.Index,
12160 internal: bool,12066 options: Metadata.GlobalVar.Options,
12161) Allocator.Error!Metadata {12067) Allocator.Error!Metadata {
12162 try self.ensureUnusedMetadataCapacity(1, Metadata.GlobalVar, 0);12068 try self.ensureUnusedMetadataCapacity(1, Metadata.GlobalVar, 0);
12163 return self.debugGlobalVarAssumeCapacity(12069 return self.debugGlobalVarAssumeCapacity(
...@@ -12168,7 +12074,7 @@ pub fn debugGlobalVar(...@@ -12168,7 +12074,7 @@ pub fn debugGlobalVar(
12168 line,12074 line,
12169 ty,12075 ty,
12170 variable,12076 variable,
12171 internal,12077 options,
12172 );12078 );
12173}12079}
1217412080
...@@ -12301,7 +12207,6 @@ pub fn debugCompileUnitAssumeCapacity(...@@ -12301,7 +12207,6 @@ pub fn debugCompileUnitAssumeCapacity(
12301 producer: MetadataString,12207 producer: MetadataString,
12302 enums: Metadata,12208 enums: Metadata,
12303 globals: Metadata,12209 globals: Metadata,
12304 imports: Metadata,
12305 options: Metadata.CompileUnit.Options,12210 options: Metadata.CompileUnit.Options,
12306) Metadata {12211) Metadata {
12307 assert(!self.strip);12212 assert(!self.strip);
...@@ -12312,7 +12217,6 @@ pub fn debugCompileUnitAssumeCapacity(...@@ -12312,7 +12217,6 @@ pub fn debugCompileUnitAssumeCapacity(
12312 .producer = producer,12217 .producer = producer,
12313 .enums = enums,12218 .enums = enums,
12314 .globals = globals,12219 .globals = globals,
12315 .imports = imports,
12316 },12220 },
12317 );12221 );
12318}12222}
...@@ -12320,7 +12224,6 @@ pub fn debugCompileUnitAssumeCapacity(...@@ -12320,7 +12224,6 @@ pub fn debugCompileUnitAssumeCapacity(
12320fn debugSubprogramAssumeCapacity(12224fn debugSubprogramAssumeCapacity(
12321 self: *Builder,12225 self: *Builder,
12322 file: Metadata,12226 file: Metadata,
12323 scope: Metadata,
12324 name: MetadataString,12227 name: MetadataString,
12325 linkage_name: MetadataString,12228 linkage_name: MetadataString,
12326 line: u32,12229 line: u32,
...@@ -12334,7 +12237,6 @@ fn debugSubprogramAssumeCapacity(...@@ -12334,7 +12237,6 @@ fn debugSubprogramAssumeCapacity(
12334 @as(u3, @truncate(@as(u32, @bitCast(options.sp_flags)) >> 2)));12237 @as(u3, @truncate(@as(u32, @bitCast(options.sp_flags)) >> 2)));
12335 return self.metadataDistinctAssumeCapacity(tag, Metadata.Subprogram{12238 return self.metadataDistinctAssumeCapacity(tag, Metadata.Subprogram{
12336 .file = file,12239 .file = file,
12337 .scope = scope,
12338 .name = name,12240 .name = name,
12339 .linkage_name = linkage_name,12241 .linkage_name = linkage_name,
12340 .line = line,12242 .line = line,
...@@ -12418,7 +12320,6 @@ fn debugStructTypeAssumeCapacity(...@@ -12418,7 +12320,6 @@ fn debugStructTypeAssumeCapacity(
12418 size_in_bits: u64,12320 size_in_bits: u64,
12419 align_in_bits: u64,12321 align_in_bits: u64,
12420 fields_tuple: Metadata,12322 fields_tuple: Metadata,
12421 is_byref: bool,
12422) Metadata {12323) Metadata {
12423 assert(!self.strip);12324 assert(!self.strip);
12424 return self.debugCompositeTypeAssumeCapacity(12325 return self.debugCompositeTypeAssumeCapacity(
...@@ -12431,7 +12332,6 @@ fn debugStructTypeAssumeCapacity(...@@ -12431,7 +12332,6 @@ fn debugStructTypeAssumeCapacity(
12431 size_in_bits,12332 size_in_bits,
12432 align_in_bits,12333 align_in_bits,
12433 fields_tuple,12334 fields_tuple,
12434 is_byref,
12435 );12335 );
12436}12336}
1243712337
...@@ -12445,7 +12345,6 @@ fn debugUnionTypeAssumeCapacity(...@@ -12445,7 +12345,6 @@ fn debugUnionTypeAssumeCapacity(
12445 size_in_bits: u64,12345 size_in_bits: u64,
12446 align_in_bits: u64,12346 align_in_bits: u64,
12447 fields_tuple: Metadata,12347 fields_tuple: Metadata,
12448 is_byref: bool,
12449) Metadata {12348) Metadata {
12450 assert(!self.strip);12349 assert(!self.strip);
12451 return self.debugCompositeTypeAssumeCapacity(12350 return self.debugCompositeTypeAssumeCapacity(
...@@ -12458,7 +12357,6 @@ fn debugUnionTypeAssumeCapacity(...@@ -12458,7 +12357,6 @@ fn debugUnionTypeAssumeCapacity(
12458 size_in_bits,12357 size_in_bits,
12459 align_in_bits,12358 align_in_bits,
12460 fields_tuple,12359 fields_tuple,
12461 is_byref,
12462 );12360 );
12463}12361}
1246412362
...@@ -12484,7 +12382,6 @@ fn debugEnumerationTypeAssumeCapacity(...@@ -12484,7 +12382,6 @@ fn debugEnumerationTypeAssumeCapacity(
12484 size_in_bits,12382 size_in_bits,
12485 align_in_bits,12383 align_in_bits,
12486 fields_tuple,12384 fields_tuple,
12487 false, // is_byref
12488 );12385 );
12489}12386}
1249012387
...@@ -12510,7 +12407,6 @@ fn debugArrayTypeAssumeCapacity(...@@ -12510,7 +12407,6 @@ fn debugArrayTypeAssumeCapacity(
12510 size_in_bits,12407 size_in_bits,
12511 align_in_bits,12408 align_in_bits,
12512 fields_tuple,12409 fields_tuple,
12513 size_in_bits > 0, // is_byref
12514 );12410 );
12515}12411}
1251612412
...@@ -12536,7 +12432,6 @@ fn debugVectorTypeAssumeCapacity(...@@ -12536,7 +12432,6 @@ fn debugVectorTypeAssumeCapacity(
12536 size_in_bits,12432 size_in_bits,
12537 align_in_bits,12433 align_in_bits,
12538 fields_tuple,12434 fields_tuple,
12539 false,
12540 );12435 );
12541}12436}
1254212437
...@@ -12551,7 +12446,6 @@ fn debugCompositeTypeAssumeCapacity(...@@ -12551,7 +12446,6 @@ fn debugCompositeTypeAssumeCapacity(
12551 size_in_bits: u64,12446 size_in_bits: u64,
12552 align_in_bits: u64,12447 align_in_bits: u64,
12553 fields_tuple: Metadata,12448 fields_tuple: Metadata,
12554 is_byref: bool,
12555) Metadata {12449) Metadata {
12556 assert(!self.strip);12450 assert(!self.strip);
12557 return self.metadataSimpleAssumeCapacity(tag, Metadata.CompositeType{12451 return self.metadataSimpleAssumeCapacity(tag, Metadata.CompositeType{
...@@ -12565,7 +12459,6 @@ fn debugCompositeTypeAssumeCapacity(...@@ -12565,7 +12459,6 @@ fn debugCompositeTypeAssumeCapacity(
12565 .align_in_bits_lo = @truncate(align_in_bits),12459 .align_in_bits_lo = @truncate(align_in_bits),
12566 .align_in_bits_hi = @truncate(align_in_bits >> 32),12460 .align_in_bits_hi = @truncate(align_in_bits >> 32),
12567 .fields_tuple = fields_tuple,12461 .fields_tuple = fields_tuple,
12568 .flags = .{ .is_byref = is_byref },
12569 });12462 });
12570}12463}
1257112464
...@@ -12876,11 +12769,11 @@ fn debugGlobalVarAssumeCapacity(...@@ -12876,11 +12769,11 @@ fn debugGlobalVarAssumeCapacity(
12876 line: u32,12769 line: u32,
12877 ty: Metadata,12770 ty: Metadata,
12878 variable: Variable.Index,12771 variable: Variable.Index,
12879 internal: bool,12772 options: Metadata.GlobalVar.Options,
12880) Metadata {12773) Metadata {
12881 assert(!self.strip);12774 assert(!self.strip);
12882 return self.metadataDistinctAssumeCapacity(12775 return self.metadataDistinctAssumeCapacity(
12883 if (internal) .@"global_var local" else .global_var,12776 if (options.local) .@"global_var local" else .global_var,
12884 Metadata.GlobalVar{12777 Metadata.GlobalVar{
12885 .name = name,12778 .name = name,
12886 .linkage_name = linkage_name,12779 .linkage_name = linkage_name,
...@@ -13911,7 +13804,6 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -13911,7 +13804,6 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
13911 },13804 },
13912 .enums = extra.enums,13805 .enums = extra.enums,
13913 .globals = extra.globals,13806 .globals = extra.globals,
13914 .imports = extra.imports,
13915 }, metadata_adapter);13807 }, metadata_adapter);
13916 },13808 },
13917 .subprogram,13809 .subprogram,
...@@ -13926,7 +13818,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -13926,7 +13818,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
13926 const extra = self.metadataExtraData(Metadata.Subprogram, data);13818 const extra = self.metadataExtraData(Metadata.Subprogram, data);
1392713819
13928 try metadata_block.writeAbbrevAdapted(MetadataBlock.Subprogram{13820 try metadata_block.writeAbbrevAdapted(MetadataBlock.Subprogram{
13929 .scope = extra.scope,13821 .scope = extra.file,
13930 .name = extra.name,13822 .name = extra.name,
13931 .linkage_name = extra.linkage_name,13823 .linkage_name = extra.linkage_name,
13932 .file = extra.file,13824 .file = extra.file,
...@@ -14000,24 +13892,18 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14000,24 +13892,18 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14000 .underlying_type = extra.underlying_type,13892 .underlying_type = extra.underlying_type,
14001 .size_in_bits = extra.bitSize(),13893 .size_in_bits = extra.bitSize(),
14002 .align_in_bits = extra.bitAlign(),13894 .align_in_bits = extra.bitAlign(),
14003 .flags = .{13895 .flags = if (kind == .composite_vector_type) .{ .Vector = true } else .{},
14004 .Vector = kind == .composite_vector_type,
14005 .EnumClass = kind == .composite_enumeration_type,
14006 .TypePassbyReference = extra.flags.is_byref,
14007 },
14008 .elements = extra.fields_tuple,13896 .elements = extra.fields_tuple,
14009 }, metadata_adapter);13897 }, metadata_adapter);
14010 },13898 },
14011 .derived_pointer_type,13899 .derived_pointer_type,
14012 .derived_member_type,13900 .derived_member_type,
14013 .derived_typedef,
14014 => |kind| {13901 => |kind| {
14015 const extra = self.metadataExtraData(Metadata.DerivedType, data);13902 const extra = self.metadataExtraData(Metadata.DerivedType, data);
14016 try metadata_block.writeAbbrevAdapted(MetadataBlock.DerivedType{13903 try metadata_block.writeAbbrevAdapted(MetadataBlock.DerivedType{
14017 .tag = switch (kind) {13904 .tag = switch (kind) {
14018 .derived_pointer_type => DW.TAG.pointer_type,13905 .derived_pointer_type => DW.TAG.pointer_type,
14019 .derived_member_type => DW.TAG.member,13906 .derived_member_type => DW.TAG.member,
14020 .derived_typedef => DW.TAG.typedef,
14021 else => unreachable,13907 else => unreachable,
14022 },13908 },
14023 .name = extra.name,13909 .name = extra.name,
...@@ -14028,20 +13914,6 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co...@@ -14028,20 +13914,6 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
14028 .size_in_bits = extra.bitSize(),13914 .size_in_bits = extra.bitSize(),
14029 .align_in_bits = extra.bitAlign(),13915 .align_in_bits = extra.bitAlign(),
14030 .offset_in_bits = extra.bitOffset(),13916 .offset_in_bits = extra.bitOffset(),
14031 .flags = .{
14032 .StaticMember = false,
14033 },
14034 }, metadata_adapter);
14035 },
14036 .imported_declaration => {
14037 const extra = self.metadataExtraData(Metadata.ImportedEntity, data);
14038 try metadata_block.writeAbbrevAdapted(MetadataBlock.ImportedEntity{
14039 .tag = DW.TAG.imported_declaration,
14040 .scope = extra.scope,
14041 .entity = extra.entity,
14042 .line = extra.line,
14043 .name = extra.name,
14044 .file = extra.file,
14045 }, metadata_adapter);13917 }, metadata_adapter);
14046 },13918 },
14047 .subroutine_type => {13919 .subroutine_type => {
src/codegen/llvm/ir.zig+3-27
...@@ -649,7 +649,6 @@ pub const MetadataBlock = struct {...@@ -649,7 +649,6 @@ pub const MetadataBlock = struct {
649 BasicType,649 BasicType,
650 CompositeType,650 CompositeType,
651 DerivedType,651 DerivedType,
652 ImportedEntity,
653 SubroutineType,652 SubroutineType,
654 Enumerator,653 Enumerator,
655 Subrange,654 Subrange,
...@@ -695,7 +694,7 @@ pub const MetadataBlock = struct {...@@ -695,7 +694,7 @@ pub const MetadataBlock = struct {
695 pub const ops = [_]AbbrevOp{694 pub const ops = [_]AbbrevOp{
696 .{ .literal = 20 },695 .{ .literal = 20 },
697 .{ .literal = 1 }, // is distinct696 .{ .literal = 1 }, // is distinct
698 .{ .literal = std.dwarf.LANG.C_plus_plus_11 }, // source language697 .{ .literal = std.dwarf.LANG.C99 }, // source language
699 MetadataAbbrev, // file698 MetadataAbbrev, // file
700 MetadataAbbrev, // producer699 MetadataAbbrev, // producer
701 .{ .fixed = 1 }, // isOptimized700 .{ .fixed = 1 }, // isOptimized
...@@ -707,7 +706,7 @@ pub const MetadataBlock = struct {...@@ -707,7 +706,7 @@ pub const MetadataBlock = struct {
707 .{ .literal = 0 }, // retained types706 .{ .literal = 0 }, // retained types
708 .{ .literal = 0 }, // subprograms707 .{ .literal = 0 }, // subprograms
709 MetadataAbbrev, // globals708 MetadataAbbrev, // globals
710 MetadataAbbrev, // imported entities709 .{ .literal = 0 }, // imported entities
711 .{ .literal = 0 }, // DWO ID710 .{ .literal = 0 }, // DWO ID
712 .{ .literal = 0 }, // macros711 .{ .literal = 0 }, // macros
713 .{ .literal = 0 }, // split debug inlining712 .{ .literal = 0 }, // split debug inlining
...@@ -723,7 +722,6 @@ pub const MetadataBlock = struct {...@@ -723,7 +722,6 @@ pub const MetadataBlock = struct {
723 is_optimized: bool,722 is_optimized: bool,
724 enums: Builder.Metadata,723 enums: Builder.Metadata,
725 globals: Builder.Metadata,724 globals: Builder.Metadata,
726 imports: Builder.Metadata,
727 };725 };
728726
729 pub const Subprogram = struct {727 pub const Subprogram = struct {
...@@ -865,7 +863,7 @@ pub const MetadataBlock = struct {...@@ -865,7 +863,7 @@ pub const MetadataBlock = struct {
865 .{ .vbr = 6 }, // size in bits863 .{ .vbr = 6 }, // size in bits
866 .{ .vbr = 6 }, // align in bits864 .{ .vbr = 6 }, // align in bits
867 .{ .vbr = 6 }, // offset in bits865 .{ .vbr = 6 }, // offset in bits
868 .{ .fixed = 32 }, // flags866 .{ .literal = 0 }, // flags
869 .{ .literal = 0 }, // extra data867 .{ .literal = 0 }, // extra data
870 };868 };
871869
...@@ -878,28 +876,6 @@ pub const MetadataBlock = struct {...@@ -878,28 +876,6 @@ pub const MetadataBlock = struct {
878 size_in_bits: u64,876 size_in_bits: u64,
879 align_in_bits: u64,877 align_in_bits: u64,
880 offset_in_bits: u64,878 offset_in_bits: u64,
881 flags: Builder.Metadata.DIFlags,
882 };
883
884 pub const ImportedEntity = struct {
885 pub const ops = [_]AbbrevOp{
886 .{ .literal = 31 },
887 .{ .literal = 0 }, // is distinct
888 .{ .fixed = 32 }, // tag
889 MetadataAbbrev, // scope
890 MetadataAbbrev, // entity
891 LineAbbrev, // line
892 MetadataAbbrev, // name
893 MetadataAbbrev, // file
894 .{ .literal = 0 }, // elements
895 };
896
897 tag: u32,
898 scope: Builder.Metadata,
899 entity: Builder.Metadata,
900 line: u32,
901 name: Builder.MetadataString,
902 file: Builder.Metadata,
903 };879 };
904880
905 pub const SubroutineType = struct {881 pub const SubroutineType = struct {
test/cases/llvm/debug_types.zig deleted-23
...@@ -1,23 +0,0 @@
1const Ty = struct {
2 pub const A = void;
3 pub const B = @Vector(2, u0);
4 pub const C = u0;
5 pub const D = enum (u0) {};
6 pub const E = type;
7 pub const F = 1;
8 pub const G = 1.0;
9 pub const H = undefined;
10 pub const I = null;
11 pub const J = .foo;
12};
13pub fn main() void {
14 inline for (@typeInfo(Ty).Struct.decls) |d|{
15 _ = @field(Ty, d.name);
16 }
17}
18
19// compile
20// output_mode=Exe
21// backend=llvm
22// target=x86_64-linux,x86_64-macos
23//
\ No newline at end of file