Skip to content

Commit e83607f

Browse files
committed
Dwarf: remove comptime parameters from generic origin functions
Since generic instantiations are missing comptime arguments in Air, they must be removed from the generic origins too.
1 parent 8e0a4ca commit e83607f

File tree

1 file changed

+33
-26
lines changed

1 file changed

+33
-26
lines changed

src/link/Dwarf.zig

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,9 +2008,9 @@ pub const WipNav = struct {
20082008
.decl_const_runtime_bits,
20092009
.decl_const_comptime_state,
20102010
.decl_const_runtime_bits_comptime_state,
2011-
.decl_empty_func,
2011+
.decl_nullary_func,
20122012
.decl_func,
2013-
.decl_empty_func_generic,
2013+
.decl_nullary_func_generic,
20142014
.decl_func_generic,
20152015
=> false,
20162016
.generic_decl_var,
@@ -2626,8 +2626,8 @@ pub fn finishWipNavFunc(
26262626
abbrev_code_buf,
26272627
try dwarf.refAbbrevCode(switch (abbrev_code) {
26282628
else => unreachable,
2629-
.decl_func => .decl_empty_func,
2630-
.decl_instance_func => .decl_instance_empty_func,
2629+
.decl_func => .decl_nullary_func,
2630+
.decl_instance_func => .decl_instance_nullary_func,
26312631
}),
26322632
);
26332633
}
@@ -3012,29 +3012,34 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo
30123012
if (nav_gop.found_existing) switch (try dwarf.debug_info.declAbbrevCode(wip_nav.unit, nav_gop.value_ptr.*)) {
30133013
.null => {},
30143014
else => unreachable,
3015-
.decl_empty_func, .decl_func, .decl_instance_empty_func, .decl_instance_func => return,
3016-
.decl_empty_func_generic,
3015+
.decl_nullary_func, .decl_func, .decl_instance_nullary_func, .decl_instance_func => return,
3016+
.decl_nullary_func_generic,
30173017
.decl_func_generic,
3018-
.decl_instance_empty_func_generic,
3018+
.decl_instance_nullary_func_generic,
30193019
.decl_instance_func_generic,
30203020
=> dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(nav_gop.value_ptr.*).clear(),
30213021
} else nav_gop.value_ptr.* = try dwarf.addCommonEntry(wip_nav.unit);
30223022
wip_nav.entry = nav_gop.value_ptr.*;
30233023

30243024
const func_type = ip.indexToKey(func.ty).func_type;
3025+
const is_nullary = !func_type.is_var_args and for (0..func_type.param_types.len) |param_index| {
3026+
if (!func_type.paramIsComptime(std.math.cast(u5, param_index) orelse break false)) break false;
3027+
} else true;
30253028
const diw = wip_nav.debug_info.writer(dwarf.gpa);
3026-
try wip_nav.declCommon(if (func_type.param_types.len > 0 or func_type.is_var_args) .{
3027-
.decl = .decl_func_generic,
3029+
try wip_nav.declCommon(if (is_nullary) .{
3030+
.decl = .decl_nullary_func_generic,
30283031
.generic_decl = .generic_decl_func,
3029-
.decl_instance = .decl_instance_func_generic,
3032+
.decl_instance = .decl_instance_nullary_func_generic,
30303033
} else .{
3031-
.decl = .decl_empty_func_generic,
3034+
.decl = .decl_func_generic,
30323035
.generic_decl = .generic_decl_func,
3033-
.decl_instance = .decl_instance_empty_func_generic,
3036+
.decl_instance = .decl_instance_func_generic,
30343037
}, &nav, inst_info.file, &decl);
30353038
try wip_nav.refType(.fromInterned(func_type.return_type));
3036-
if (func_type.param_types.len > 0 or func_type.is_var_args) {
3039+
if (!is_nullary) {
30373040
for (0..func_type.param_types.len) |param_index| {
3041+
if (std.math.cast(u5, param_index)) |small_param_index|
3042+
if (func_type.paramIsComptime(small_param_index)) continue;
30383043
try wip_nav.abbrevCode(.func_type_param);
30393044
try wip_nav.refType(.fromInterned(func_type.param_types.get(ip)[param_index]));
30403045
}
@@ -3568,12 +3573,14 @@ fn updateLazyType(
35683573
};
35693574
try diw.writeByte(@intFromEnum(cc));
35703575
try wip_nav.refType(.fromInterned(func_type.return_type));
3571-
for (0..func_type.param_types.len) |param_index| {
3572-
try wip_nav.abbrevCode(.func_type_param);
3573-
try wip_nav.refType(.fromInterned(func_type.param_types.get(ip)[param_index]));
3576+
if (!is_nullary) {
3577+
for (0..func_type.param_types.len) |param_index| {
3578+
try wip_nav.abbrevCode(.func_type_param);
3579+
try wip_nav.refType(.fromInterned(func_type.param_types.get(ip)[param_index]));
3580+
}
3581+
if (func_type.is_var_args) try wip_nav.abbrevCode(.is_var_args);
3582+
try uleb128(diw, @intFromEnum(AbbrevCode.null));
35743583
}
3575-
if (func_type.is_var_args) try wip_nav.abbrevCode(.is_var_args);
3576-
if (!is_nullary) try uleb128(diw, @intFromEnum(AbbrevCode.null));
35773584
},
35783585
.error_set_type => |error_set_type| {
35793586
try wip_nav.abbrevCode(if (error_set_type.names.len == 0) .generated_empty_enum_type else .generated_enum_type);
@@ -4787,9 +4794,9 @@ const AbbrevCode = enum {
47874794
decl_const_runtime_bits,
47884795
decl_const_comptime_state,
47894796
decl_const_runtime_bits_comptime_state,
4790-
decl_empty_func,
4797+
decl_nullary_func,
47914798
decl_func,
4792-
decl_empty_func_generic,
4799+
decl_nullary_func_generic,
47934800
decl_func_generic,
47944801
generic_decl_var,
47954802
generic_decl_const,
@@ -4806,9 +4813,9 @@ const AbbrevCode = enum {
48064813
decl_instance_const_runtime_bits,
48074814
decl_instance_const_comptime_state,
48084815
decl_instance_const_runtime_bits_comptime_state,
4809-
decl_instance_empty_func,
4816+
decl_instance_nullary_func,
48104817
decl_instance_func,
4811-
decl_instance_empty_func_generic,
4818+
decl_instance_nullary_func_generic,
48124819
decl_instance_func_generic,
48134820
// the rest are unrestricted other than empty variants must not be longer
48144821
// than the non-empty variant, and so should appear first
@@ -5019,7 +5026,7 @@ const AbbrevCode = enum {
50195026
.{ .ZIG_comptime_value, .ref_addr },
50205027
},
50215028
},
5022-
.decl_empty_func = .{
5029+
.decl_nullary_func = .{
50235030
.tag = .subprogram,
50245031
.attrs = decl_abbrev_common_attrs ++ .{
50255032
.{ .linkage_name, .strp },
@@ -5044,7 +5051,7 @@ const AbbrevCode = enum {
50445051
.{ .noreturn, .flag },
50455052
},
50465053
},
5047-
.decl_empty_func_generic = .{
5054+
.decl_nullary_func_generic = .{
50485055
.tag = .subprogram,
50495056
.attrs = decl_abbrev_common_attrs ++ .{
50505057
.{ .type, .ref_addr },
@@ -5167,7 +5174,7 @@ const AbbrevCode = enum {
51675174
.{ .ZIG_comptime_value, .ref_addr },
51685175
},
51695176
},
5170-
.decl_instance_empty_func = .{
5177+
.decl_instance_nullary_func = .{
51715178
.tag = .subprogram,
51725179
.attrs = decl_instance_abbrev_common_attrs ++ .{
51735180
.{ .linkage_name, .strp },
@@ -5192,7 +5199,7 @@ const AbbrevCode = enum {
51925199
.{ .noreturn, .flag },
51935200
},
51945201
},
5195-
.decl_instance_empty_func_generic = .{
5202+
.decl_instance_nullary_func_generic = .{
51965203
.tag = .subprogram,
51975204
.attrs = decl_instance_abbrev_common_attrs ++ .{
51985205
.{ .type, .ref_addr },

0 commit comments

Comments
 (0)