| ... | @@ -717,16 +717,23 @@ pub const WipFunc = struct { | ... | @@ -717,16 +717,23 @@ pub const WipFunc = struct { |
| 717 | pub const Debug = struct { | 717 | pub const Debug = struct { |
| 718 | wip_func: WipFunc, | 718 | wip_func: WipFunc, |
| 719 | pt: Zcu.PerThread, | 719 | pt: Zcu.PerThread, |
| 720 | empty: bool, | 720 | is_empty: bool, |
| | 721 | empty_abbrev_code: AbbrevCode, |
| 721 | blocks: std.ArrayList(struct { | 722 | blocks: std.ArrayList(struct { |
| 722 | abbrev_code: u32, | 723 | abbrev_code_offset: usize, |
| 723 | low_pc_off: usize, | 724 | low_pc: usize, |
| 724 | high_pc: u32, | 725 | high_pc_offset: usize, |
| 725 | }), | 726 | }), |
| 726 | info_writer: link.MappedFile.Node.Writer, | 727 | info_writer: link.MappedFile.Node.Writer, |
| 727 | info_func_length_offset: usize, | 728 | info_func_length_offset: usize, |
| 728 | line_writer: link.MappedFile.Node.Writer, | 729 | line_writer: link.MappedFile.Node.Writer, |
| 729 | | 730 | |
| | 731 | pub fn init(debug: *Debug, pt: Zcu.PerThread) void { |
| | 732 | debug.pt = pt; |
| | 733 | debug.is_empty = true; |
| | 734 | debug.blocks = .empty; |
| | 735 | } |
| | 736 | |
| 730 | pub fn deinit(debug: *Debug) void { | 737 | pub fn deinit(debug: *Debug) void { |
| 731 | const gpa = debug.pt.zcu.gpa; | 738 | const gpa = debug.pt.zcu.gpa; |
| 732 | debug.line_writer.deinit(); | 739 | debug.line_writer.deinit(); |
| ... | @@ -760,15 +767,24 @@ pub const WipFunc = struct { | ... | @@ -760,15 +767,24 @@ pub const WipFunc = struct { |
| 760 | const decl = zf.zir.?.getDeclaration(inst_info.inst); | 767 | const decl = zf.zir.?.getDeclaration(inst_info.inst); |
| 761 | const di_nw = &debug.info_writer; | 768 | const di_nw = &debug.info_writer; |
| 762 | const di_w = &di_nw.interface; | 769 | const di_w = &di_nw.interface; |
| 763 | try dwarf.abbrevCode(di_nw, .decl_func); | 770 | const parent_ty: Type = .fromInterned(ip.namespacePtr(switch (func.generic_owner) { |
| 764 | try dwarf.refType(pt, di_nw, .fromInterned(ip.namespacePtr(switch (func.generic_owner) { | | |
| 765 | .none => nav, | | |
| 766 | else => |generic_owner| ip.getNav(zcu.funcInfo(generic_owner).owner_nav), | 771 | else => |generic_owner| ip.getNav(zcu.funcInfo(generic_owner).owner_nav), |
| 767 | }.analysis.?.namespace).owner_type)); | 772 | .none => nav, |
| 768 | try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian); | 773 | }.analysis.?.namespace).owner_type); |
| 769 | try di_w.writeUleb128(decl.src_column + 1); | 774 | if (func.generic_owner != .none or parent_ty.getCaptures(zcu).len > 0) { |
| 770 | try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private); | 775 | debug.empty_abbrev_code = .decl_instance_empty_func; |
| 771 | try dwarf.strx(di_nw, nav.name.toSlice(ip)); | 776 | try dwarf.abbrevCode(di_nw, .decl_instance_func); |
| | 777 | try dwarf.refType(pt, di_nw, parent_ty); |
| | 778 | try dwarf.secOffset(di_nw, try dwarf.getConstDecl(pt, debug.wip_func.func), 0); |
| | 779 | } else { |
| | 780 | debug.empty_abbrev_code = .decl_empty_func; |
| | 781 | try dwarf.abbrevCode(di_nw, .decl_func); |
| | 782 | try dwarf.refType(pt, di_nw, parent_ty); |
| | 783 | try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian); |
| | 784 | try di_w.writeUleb128(decl.src_column + 1); |
| | 785 | try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private); |
| | 786 | try dwarf.strx(di_nw, nav.name.toSlice(ip)); |
| | 787 | } |
| 772 | try dwarf.strx(di_nw, switch (decl.linkage) { | 788 | try dwarf.strx(di_nw, switch (decl.linkage) { |
| 773 | .normal => nav.fqn, | 789 | .normal => nav.fqn, |
| 774 | .@"extern", .@"export" => nav.name, | 790 | .@"extern", .@"export" => nav.name, |
| ... | @@ -850,10 +866,10 @@ pub const WipFunc = struct { | ... | @@ -850,10 +866,10 @@ pub const WipFunc = struct { |
| 850 | @intCast(func_length), | 866 | @intCast(func_length), |
| 851 | dwarf.endian, | 867 | dwarf.endian, |
| 852 | ); | 868 | ); |
| 853 | if (debug.empty) std.leb.writeUnsignedFixed( | 869 | if (debug.is_empty) std.leb.writeUnsignedFixed( |
| 854 | AbbrevCode.decl_size, | 870 | AbbrevCode.decl_size, |
| 855 | di_w.buffered()[0..AbbrevCode.decl_size], | 871 | di_w.buffered()[0..AbbrevCode.decl_size], |
| 856 | @intCast(try dwarf.refAbbrevCode(di_nw.mf, .decl_empty_func)), | 872 | @intCast(try dwarf.refAbbrevCode(di_nw.mf, debug.empty_abbrev_code)), |
| 857 | ) else try di_w.writeUleb128(@backingInt(AbbrevCode.null)); | 873 | ) else try di_w.writeUleb128(@backingInt(AbbrevCode.null)); |
| 858 | try dwarf.genDebugInfoPadding(di_w, di_w.unusedCapacityLen()); | 874 | try dwarf.genDebugInfoPadding(di_w, di_w.unusedCapacityLen()); |
| 859 | } | 875 | } |
| ... | @@ -891,7 +907,7 @@ pub const WipFunc = struct { | ... | @@ -891,7 +907,7 @@ pub const WipFunc = struct { |
| 891 | if (opt_name) |name| try dwarf.strx(di_nw, name); | 907 | if (opt_name) |name| try dwarf.strx(di_nw, name); |
| 892 | try dwarf.refType(debug.pt, di_nw, ty); | 908 | try dwarf.refType(debug.pt, di_nw, ty); |
| 893 | try dwarf.exprLoc(di_nw, loc); | 909 | try dwarf.exprLoc(di_nw, loc); |
| 894 | debug.empty = false; | 910 | debug.is_empty = false; |
| 895 | } | 911 | } |
| 896 | | 912 | |
| 897 | pub const LocalConstTag = enum { comptime_arg, local_const }; | 913 | pub const LocalConstTag = enum { comptime_arg, local_const }; |
| ... | @@ -944,7 +960,7 @@ pub const WipFunc = struct { | ... | @@ -944,7 +960,7 @@ pub const WipFunc = struct { |
| 944 | try dwarf.refType(pt, di_nw, ty); | 960 | try dwarf.refType(pt, di_nw, ty); |
| 945 | if (ty_class.hasRuntimeBits()) try dwarf.blockConst(pt, di_nw, val); | 961 | if (ty_class.hasRuntimeBits()) try dwarf.blockConst(pt, di_nw, val); |
| 946 | if (ty_class.comptimeOnly()) try dwarf.refConst(pt, di_nw, val); | 962 | if (ty_class.comptimeOnly()) try dwarf.refConst(pt, di_nw, val); |
| 947 | debug.empty = false; | 963 | debug.is_empty = false; |
| 948 | } | 964 | } |
| 949 | | 965 | |
| 950 | pub fn genVarArgsDebugInfo(debug: *Debug) link.Error!void { | 966 | pub fn genVarArgsDebugInfo(debug: *Debug) link.Error!void { |
| ... | @@ -955,7 +971,7 @@ pub const WipFunc = struct { | ... | @@ -955,7 +971,7 @@ pub const WipFunc = struct { |
| 955 | } | 971 | } |
| 956 | fn genVarArgsDebugInfoInner(debug: *Debug) link.EmitError!void { | 972 | fn genVarArgsDebugInfoInner(debug: *Debug) link.EmitError!void { |
| 957 | try debug.wip_func.dwarf.abbrevCode(&debug.info_writer, .is_var_args); | 973 | try debug.wip_func.dwarf.abbrevCode(&debug.info_writer, .is_var_args); |
| 958 | debug.empty = false; | 974 | debug.is_empty = false; |
| 959 | } | 975 | } |
| 960 | | 976 | |
| 961 | pub fn advanceLineAndPc( | 977 | pub fn advanceLineAndPc( |
| ... | @@ -1056,62 +1072,67 @@ pub const WipFunc = struct { | ... | @@ -1056,62 +1072,67 @@ pub const WipFunc = struct { |
| 1056 | try debug.line_writer.interface.writeByte(DW.LNS.set_epilogue_begin); | 1072 | try debug.line_writer.interface.writeByte(DW.LNS.set_epilogue_begin); |
| 1057 | } | 1073 | } |
| 1058 | | 1074 | |
| 1059 | pub fn enterBlock(debug: *Debug, code_off: usize) link.Error!void { | 1075 | pub fn enterBlock(debug: *Debug, code_offset: usize) link.Error!void { |
| 1060 | return debug.enterBlockInner(code_off) catch |err| switch (err) { | 1076 | return debug.enterBlockInner(code_offset) catch |err| switch (err) { |
| 1061 | else => |e| e, | 1077 | else => |e| e, |
| 1062 | error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer), | 1078 | error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer), |
| 1063 | }; | 1079 | }; |
| 1064 | } | 1080 | } |
| 1065 | fn enterBlockInner(debug: *Debug, code_off: usize) link.EmitError!void { | 1081 | fn enterBlockInner(debug: *Debug, code_offset: usize) link.EmitError!void { |
| 1066 | const dwarf = debug.wip_func.dwarf; | 1082 | const dwarf = debug.wip_func.dwarf; |
| 1067 | const block = try debug.blocks.addOne(dwarf.lf.comp.gpa); | 1083 | const block = try debug.blocks.addOne(dwarf.lf.comp.gpa); |
| 1068 | | 1084 | |
| 1069 | const di_nw = &debug.info_writer; | 1085 | const di_nw = &debug.info_writer; |
| 1070 | const di_w = &di_nw.interface; | 1086 | const di_w = &di_nw.interface; |
| 1071 | block.abbrev_code = @intCast(di_w.end); | 1087 | block.abbrev_code_offset = di_w.end; |
| 1072 | try dwarf.abbrevCode(di_nw, .block); | 1088 | try dwarf.abbrevCode(di_nw, .block); |
| 1073 | block.low_pc_off = code_off; | 1089 | block.low_pc = code_offset; |
| 1074 | try dwarf.addrSym(di_nw, debug.wip_func.func_si, code_off); | 1090 | try dwarf.addrSym(di_nw, debug.wip_func.func_si, code_offset); |
| 1075 | block.high_pc = @intCast(di_w.end); | 1091 | block.high_pc_offset = di_w.end; |
| 1076 | try di_w.writeInt(u32, 0, dwarf.endian); | 1092 | try di_w.writeInt(u32, 0, dwarf.endian); |
| 1077 | debug.empty = true; | 1093 | debug.is_empty = true; |
| 1078 | } | 1094 | } |
| 1079 | | 1095 | |
| 1080 | pub fn leaveBlock(debug: *Debug, code_off: usize) link.Error!void { | 1096 | pub fn leaveBlock(debug: *Debug, code_offset: usize) link.Error!void { |
| 1081 | return debug.leaveBlockInner(code_off) catch |err| switch (err) { | 1097 | return debug.leaveBlockInner(code_offset) catch |err| switch (err) { |
| 1082 | else => |e| e, | 1098 | else => |e| e, |
| 1083 | error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer), | 1099 | error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer), |
| 1084 | }; | 1100 | }; |
| 1085 | } | 1101 | } |
| 1086 | fn leaveBlockInner(debug: *Debug, code_off: usize) link.EmitError!void { | 1102 | fn leaveBlockInner(debug: *Debug, code_offset: usize) link.EmitError!void { |
| 1087 | const dwarf = debug.wip_func.dwarf; | 1103 | const dwarf = debug.wip_func.dwarf; |
| 1088 | const block = debug.blocks.pop().?; | 1104 | const block = debug.blocks.pop().?; |
| 1089 | | 1105 | |
| 1090 | const di_nw = &debug.info_writer; | 1106 | const di_nw = &debug.info_writer; |
| 1091 | const di_w = &di_nw.interface; | 1107 | const di_w = &di_nw.interface; |
| 1092 | const block_size = comptime uleb128Size(@backingInt(AbbrevCode.block)); | 1108 | const block_size = comptime uleb128Size(@backingInt(AbbrevCode.block)); |
| 1093 | if (debug.empty) std.leb.writeUnsignedFixed( | 1109 | if (debug.is_empty) std.leb.writeUnsignedFixed( |
| 1094 | block_size, | 1110 | block_size, |
| 1095 | di_w.buffered()[block.abbrev_code..][0..block_size], | 1111 | di_w.buffered()[block.abbrev_code_offset..][0..block_size], |
| 1096 | @intCast(try dwarf.refAbbrevCode(di_nw.mf, .empty_block)), | 1112 | @intCast(try dwarf.refAbbrevCode(di_nw.mf, .empty_block)), |
| 1097 | ) else try di_w.writeUleb128(@backingInt(AbbrevCode.null)); | 1113 | ) else try di_w.writeUleb128(@backingInt(AbbrevCode.null)); |
| 1098 | std.mem.writeInt( | 1114 | std.mem.writeInt( |
| 1099 | u32, | 1115 | u32, |
| 1100 | di_nw.interface.buffered()[block.high_pc..][0..4], | 1116 | di_nw.interface.buffered()[block.high_pc_offset..][0..4], |
| 1101 | @intCast(code_off - block.low_pc_off), | 1117 | @intCast(code_offset - block.low_pc), |
| 1102 | dwarf.endian, | 1118 | dwarf.endian, |
| 1103 | ); | 1119 | ); |
| 1104 | debug.empty = false; | 1120 | debug.is_empty = false; |
| 1105 | } | 1121 | } |
| 1106 | | 1122 | |
| 1107 | pub fn enterInlineFunc( | 1123 | pub fn enterInlineFunc( |
| 1108 | debug: *Debug, | 1124 | debug: *Debug, |
| 1109 | func: InternPool.Index, | 1125 | func: InternPool.Index, |
| 1110 | code_off: usize, | 1126 | code_offset: usize, |
| 1111 | line: u32, | 1127 | line: u32, |
| 1112 | column: u32, | 1128 | column: u32, |
| 1113 | ) link.Error!void { | 1129 | ) link.Error!void { |
| 1114 | return debug.enterInlineFuncInner(func, code_off, line, column) catch |err| switch (err) { | 1130 | return debug.enterInlineFuncInner( |
| | 1131 | func, |
| | 1132 | code_offset, |
| | 1133 | line, |
| | 1134 | column, |
| | 1135 | ) catch |err| switch (err) { |
| 1115 | else => |e| e, | 1136 | else => |e| e, |
| 1116 | error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer), | 1137 | error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer), |
| 1117 | }; | 1138 | }; |
| ... | @@ -1119,7 +1140,7 @@ pub const WipFunc = struct { | ... | @@ -1119,7 +1140,7 @@ pub const WipFunc = struct { |
| 1119 | fn enterInlineFuncInner( | 1140 | fn enterInlineFuncInner( |
| 1120 | debug: *Debug, | 1141 | debug: *Debug, |
| 1121 | func: InternPool.Index, | 1142 | func: InternPool.Index, |
| 1122 | code_off: usize, | 1143 | code_offset: usize, |
| 1123 | line: u32, | 1144 | line: u32, |
| 1124 | column: u32, | 1145 | column: u32, |
| 1125 | ) link.EmitError!void { | 1146 | ) link.EmitError!void { |
| ... | @@ -1130,7 +1151,7 @@ pub const WipFunc = struct { | ... | @@ -1130,7 +1151,7 @@ pub const WipFunc = struct { |
| 1130 | | 1151 | |
| 1131 | const di_nw = &debug.info_writer; | 1152 | const di_nw = &debug.info_writer; |
| 1132 | const di_w = &di_nw.interface; | 1153 | const di_w = &di_nw.interface; |
| 1133 | block.abbrev_code = @intCast(di_w.end); | 1154 | block.abbrev_code_offset = di_w.end; |
| 1134 | try dwarf.abbrevCode(di_nw, .inlined_func); | 1155 | try dwarf.abbrevCode(di_nw, .inlined_func); |
| 1135 | try dwarf.refConst(pt, di_nw, .fromInterned(func)); | 1156 | try dwarf.refConst(pt, di_nw, .fromInterned(func)); |
| 1136 | try di_w.writeUleb128((if (zcu.comp.config.incremental) | 1157 | try di_w.writeUleb128((if (zcu.comp.config.incremental) |
| ... | @@ -1138,16 +1159,20 @@ pub const WipFunc = struct { | ... | @@ -1138,16 +1159,20 @@ pub const WipFunc = struct { |
| 1138 | else | 1159 | else |
| 1139 | zcu.navSrcLine(zcu.funcInfo(debug.wip_func.func).owner_nav) + 1) + line); | 1160 | zcu.navSrcLine(zcu.funcInfo(debug.wip_func.func).owner_nav) + 1) + line); |
| 1140 | try di_w.writeUleb128(column + 1); | 1161 | try di_w.writeUleb128(column + 1); |
| 1141 | block.low_pc_off = code_off; | 1162 | block.low_pc = code_offset; |
| 1142 | try dwarf.addrSym(di_nw, debug.wip_func.func_si, code_off); | 1163 | try dwarf.addrSym(di_nw, debug.wip_func.func_si, code_offset); |
| 1143 | block.high_pc = @intCast(di_w.end); | 1164 | block.high_pc_offset = di_w.end; |
| 1144 | try di_w.writeInt(u32, 0, dwarf.endian); | 1165 | try di_w.writeInt(u32, 0, dwarf.endian); |
| 1145 | try debug.setInlineFunc(func); | 1166 | try debug.setInlineFunc(func); |
| 1146 | debug.empty = true; | 1167 | debug.is_empty = true; |
| 1147 | } | 1168 | } |
| 1148 | | 1169 | |
| 1149 | pub fn leaveInlineFunc(debug: *Debug, func: InternPool.Index, code_off: usize) link.Error!void { | 1170 | pub fn leaveInlineFunc( |
| 1150 | return debug.leaveInlineFuncInner(func, code_off) catch |err| switch (err) { | 1171 | debug: *Debug, |
| | 1172 | func: InternPool.Index, |
| | 1173 | code_offset: usize, |
| | 1174 | ) link.Error!void { |
| | 1175 | return debug.leaveInlineFuncInner(func, code_offset) catch |err| switch (err) { |
| 1151 | else => |e| e, | 1176 | else => |e| e, |
| 1152 | error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer), | 1177 | error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer), |
| 1153 | }; | 1178 | }; |
| ... | @@ -1155,7 +1180,7 @@ pub const WipFunc = struct { | ... | @@ -1155,7 +1180,7 @@ pub const WipFunc = struct { |
| 1155 | fn leaveInlineFuncInner( | 1180 | fn leaveInlineFuncInner( |
| 1156 | debug: *Debug, | 1181 | debug: *Debug, |
| 1157 | func: InternPool.Index, | 1182 | func: InternPool.Index, |
| 1158 | code_off: usize, | 1183 | code_offset: usize, |
| 1159 | ) link.EmitError!void { | 1184 | ) link.EmitError!void { |
| 1160 | const dwarf = debug.wip_func.dwarf; | 1185 | const dwarf = debug.wip_func.dwarf; |
| 1161 | const block = debug.blocks.pop().?; | 1186 | const block = debug.blocks.pop().?; |
| ... | @@ -1163,19 +1188,19 @@ pub const WipFunc = struct { | ... | @@ -1163,19 +1188,19 @@ pub const WipFunc = struct { |
| 1163 | const di_nw = &debug.info_writer; | 1188 | const di_nw = &debug.info_writer; |
| 1164 | const di_w = &di_nw.interface; | 1189 | const di_w = &di_nw.interface; |
| 1165 | const inlined_func_size = comptime uleb128Size(@backingInt(AbbrevCode.inlined_func)); | 1190 | const inlined_func_size = comptime uleb128Size(@backingInt(AbbrevCode.inlined_func)); |
| 1166 | if (debug.empty) std.leb.writeUnsignedFixed( | 1191 | if (debug.is_empty) std.leb.writeUnsignedFixed( |
| 1167 | inlined_func_size, | 1192 | inlined_func_size, |
| 1168 | di_w.buffered()[block.abbrev_code..][0..inlined_func_size], | 1193 | di_w.buffered()[block.abbrev_code_offset..][0..inlined_func_size], |
| 1169 | @intCast(try dwarf.refAbbrevCode(di_nw.mf, .empty_inlined_func)), | 1194 | @intCast(try dwarf.refAbbrevCode(di_nw.mf, .empty_inlined_func)), |
| 1170 | ) else try di_w.writeUleb128(@backingInt(AbbrevCode.null)); | 1195 | ) else try di_w.writeUleb128(@backingInt(AbbrevCode.null)); |
| 1171 | std.mem.writeInt( | 1196 | std.mem.writeInt( |
| 1172 | u32, | 1197 | u32, |
| 1173 | di_w.buffered()[block.high_pc..][0..4], | 1198 | di_w.buffered()[block.high_pc_offset..][0..4], |
| 1174 | @intCast(code_off - block.low_pc_off), | 1199 | @intCast(code_offset - block.low_pc), |
| 1175 | dwarf.endian, | 1200 | dwarf.endian, |
| 1176 | ); | 1201 | ); |
| 1177 | try debug.setInlineFunc(func); | 1202 | try debug.setInlineFunc(func); |
| 1178 | debug.empty = false; | 1203 | debug.is_empty = false; |
| 1179 | } | 1204 | } |
| 1180 | | 1205 | |
| 1181 | pub fn setInlineFunc(debug: *Debug, func: InternPool.Index) link.Error!void { | 1206 | pub fn setInlineFunc(debug: *Debug, func: InternPool.Index) link.Error!void { |
| ... | @@ -1539,47 +1564,59 @@ pub fn getFuncIfExists(dwarf: *Dwarf, nav: InternPool.Nav.Index) ?Func.Index { | ... | @@ -1539,47 +1564,59 @@ pub fn getFuncIfExists(dwarf: *Dwarf, nav: InternPool.Nav.Index) ?Func.Index { |
| 1539 | return @fromBackingInt(@intCast(dwarf.funcs.getIndex(nav) orelse return null)); | 1564 | return @fromBackingInt(@intCast(dwarf.funcs.getIndex(nav) orelse return null)); |
| 1540 | } | 1565 | } |
| 1541 | | 1566 | |
| 1542 | fn getConstDeclInst(dwarf: *Dwarf, val: InternPool.Index) ?InternPool.TrackedInst.Index { | 1567 | fn getConstDeclInst(dwarf: *Dwarf, @"const": InternPool.Index) union(enum) { |
| 1543 | const ip = &dwarf.lf.comp.zcu.?.intern_pool; | 1568 | @"const": InternPool.Index, |
| 1544 | switch (ip.indexToKey(val)) { | 1569 | src_inst: InternPool.TrackedInst.Index, |
| | 1570 | } { |
| | 1571 | const zcu = dwarf.lf.comp.zcu.?; |
| | 1572 | const ip = &zcu.intern_pool; |
| | 1573 | switch (ip.indexToKey(@"const")) { |
| 1545 | else => unreachable, | 1574 | else => unreachable, |
| 1546 | .struct_type, .union_type, .enum_type, .opaque_type => |container, tag| switch (container) { | 1575 | .struct_type, .union_type, .enum_type, .opaque_type => |container, tag| switch (container) { |
| 1547 | .declared => |declared| switch (declared.captures.owned.len) { | 1576 | .declared => |declared| switch (declared.captures.owned.len) { |
| 1548 | 0 => return null, | 1577 | 0 => return .{ .@"const" = @"const" }, |
| 1549 | else => switch (tag) { | 1578 | else => return .{ .src_inst = src_inst: switch (tag) { |
| 1550 | else => unreachable, | 1579 | else => unreachable, |
| 1551 | .struct_type => { | 1580 | .struct_type => { |
| 1552 | const loaded_struct = ip.loadStructType(val); | 1581 | const loaded_struct = ip.loadStructType(@"const"); |
| 1553 | return ip.getNav(loaded_struct.name_nav.unwrap() orelse | 1582 | break :src_inst ip.getNav(loaded_struct.name_nav.unwrap() orelse |
| 1554 | return loaded_struct.zir_index).srcInst(ip); | 1583 | break :src_inst loaded_struct.zir_index).srcInst(ip); |
| 1555 | }, | 1584 | }, |
| 1556 | .union_type => { | 1585 | .union_type => { |
| 1557 | const loaded_union = ip.loadUnionType(val); | 1586 | const loaded_union = ip.loadUnionType(@"const"); |
| 1558 | return ip.getNav(loaded_union.name_nav.unwrap() orelse | 1587 | break :src_inst ip.getNav(loaded_union.name_nav.unwrap() orelse |
| 1559 | return loaded_union.zir_index).srcInst(ip); | 1588 | break :src_inst loaded_union.zir_index).srcInst(ip); |
| 1560 | }, | 1589 | }, |
| 1561 | .enum_type => { | 1590 | .enum_type => { |
| 1562 | const loaded_enum = ip.loadEnumType(val); | 1591 | const loaded_enum = ip.loadEnumType(@"const"); |
| 1563 | return ip.getNav(loaded_enum.name_nav.unwrap() orelse | 1592 | break :src_inst ip.getNav(loaded_enum.name_nav.unwrap() orelse |
| 1564 | return loaded_enum.zir_index.unwrap().?).srcInst(ip); | 1593 | break :src_inst loaded_enum.zir_index.unwrap().?).srcInst(ip); |
| 1565 | }, | 1594 | }, |
| 1566 | .opaque_type => { | 1595 | .opaque_type => { |
| 1567 | const loaded_opaque = ip.loadOpaqueType(val); | 1596 | const loaded_opaque = ip.loadOpaqueType(@"const"); |
| 1568 | return ip.getNav(loaded_opaque.name_nav.unwrap() orelse | 1597 | break :src_inst ip.getNav(loaded_opaque.name_nav.unwrap() orelse |
| 1569 | return loaded_opaque.zir_index).srcInst(ip); | 1598 | break :src_inst loaded_opaque.zir_index).srcInst(ip); |
| 1570 | }, | 1599 | }, |
| 1571 | }, | 1600 | } }, |
| 1572 | }, | 1601 | }, |
| 1573 | .reified => |reified| { | 1602 | .reified => |reified| { |
| 1574 | assert(reified.zir_index.resolve(ip).? != .main_struct_inst); | 1603 | assert(reified.zir_index.resolve(ip).? != .main_struct_inst); |
| 1575 | return reified.zir_index; | 1604 | return .{ .src_inst = reified.zir_index }; |
| 1576 | }, | 1605 | }, |
| 1577 | .generated_union_tag => unreachable, | 1606 | .generated_union_tag => unreachable, |
| 1578 | }, | 1607 | }, |
| 1579 | .func => |func| return ip.getNav(switch (func.generic_owner) { | 1608 | .func => |func| switch (func.generic_owner) { |
| 1580 | .none => func.owner_nav, | 1609 | else => |generic_owner| return .{ .@"const" = generic_owner }, |
| 1581 | else => |generic_owner| ip.indexToKey(generic_owner).func.owner_nav, | 1610 | .none => { |
| 1582 | }).srcInst(ip), | 1611 | const owner_nav = ip.getNav(func.owner_nav); |
| | 1612 | return switch (Type.fromInterned( |
| | 1613 | ip.namespacePtr(owner_nav.analysis.?.namespace).owner_type, |
| | 1614 | ).getCaptures(zcu).len) { |
| | 1615 | 0 => .{ .@"const" = @"const" }, |
| | 1616 | else => .{ .src_inst = owner_nav.srcInst(ip) }, |
| | 1617 | }; |
| | 1618 | }, |
| | 1619 | }, |
| 1583 | } | 1620 | } |
| 1584 | } | 1621 | } |
| 1585 | pub fn getConstDecl( | 1622 | pub fn getConstDecl( |
| ... | @@ -1587,10 +1624,13 @@ pub fn getConstDecl( | ... | @@ -1587,10 +1624,13 @@ pub fn getConstDecl( |
| 1587 | pt: Zcu.PerThread, | 1624 | pt: Zcu.PerThread, |
| 1588 | instance_const: InternPool.Index, | 1625 | instance_const: InternPool.Index, |
| 1589 | ) link.Error!link.MappedFile.Node.Index { | 1626 | ) link.Error!link.MappedFile.Node.Index { |
| 1590 | return dwarf.getDecl(pt, dwarf.getConstDeclInst(instance_const) orelse { | 1627 | switch (dwarf.getConstDeclInst(instance_const)) { |
| 1591 | const cpi = try dwarf.getConst(pt, .fromInterned(instance_const)); | 1628 | .@"const" => |@"const"| { |
| 1592 | return Const.get(cpi, dwarf).debug_info_ni.unwrap().?; | 1629 | const cpi = try dwarf.getConst(pt, .fromInterned(@"const")); |
| 1593 | }, .{ .@"const" = instance_const }); | 1630 | return Const.get(cpi, dwarf).debug_info_ni.unwrap().?; |
| | 1631 | }, |
| | 1632 | .src_inst => |src_inst| return dwarf.getDecl(pt, src_inst, .{ .@"const" = instance_const }), |
| | 1633 | } |
| 1594 | } | 1634 | } |
| 1595 | pub fn getGlobalDecl( | 1635 | pub fn getGlobalDecl( |
| 1596 | dwarf: *Dwarf, | 1636 | dwarf: *Dwarf, |
| ... | @@ -2259,7 +2299,7 @@ pub fn updateComptimeGlobal( | ... | @@ -2259,7 +2299,7 @@ pub fn updateComptimeGlobal( |
| 2259 | const zcu = pt.zcu; | 2299 | const zcu = pt.zcu; |
| 2260 | const ip = &zcu.intern_pool; | 2300 | const ip = &zcu.intern_pool; |
| 2261 | const nav = ip.getNav(global); | 2301 | const nav = ip.getNav(global); |
| 2262 | log.debug("updateComptimeNav({f})", .{nav.fqn.fmt(ip)}); | 2302 | log.debug("updateComptimeGlobal({f})", .{nav.fqn.fmt(ip)}); |
| 2263 | const inst_info = nav.srcInst(ip).resolveFull(ip).?; | 2303 | const inst_info = nav.srcInst(ip).resolveFull(ip).?; |
| 2264 | const nav_val: Value = .fromInterned(nav.resolved.?.value); | 2304 | const nav_val: Value = .fromInterned(nav.resolved.?.value); |
| 2265 | const decl = zcu.fileByIndex(inst_info.file).zir.?.getDeclaration(inst_info.inst); | 2305 | const decl = zcu.fileByIndex(inst_info.file).zir.?.getDeclaration(inst_info.inst); |
| ... | @@ -2298,32 +2338,32 @@ pub fn updateComptimeGlobal( | ... | @@ -2298,32 +2338,32 @@ pub fn updateComptimeGlobal( |
| 2298 | => try dwarf.genComptimeGlobal(pt, global, &decl), | 2338 | => try dwarf.genComptimeGlobal(pt, global, &decl), |
| 2299 | .struct_type => { | 2339 | .struct_type => { |
| 2300 | const loaded_struct = ip.loadStructType(nav_val.toIntern()); | 2340 | const loaded_struct = ip.loadStructType(nav_val.toIntern()); |
| 2301 | if (global.toOptional() == loaded_struct.name_nav) { | 2341 | if (loaded_struct.name_nav == global.toOptional()) { |
| 2302 | _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern()); | 2342 | _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern()); |
| 2303 | } else try dwarf.genComptimeGlobal(pt, global, &decl); | 2343 | } else try dwarf.genComptimeGlobal(pt, global, &decl); |
| 2304 | }, | 2344 | }, |
| 2305 | .enum_type => { | 2345 | .enum_type => { |
| 2306 | const loaded_enum = ip.loadEnumType(nav_val.toIntern()); | 2346 | const loaded_enum = ip.loadEnumType(nav_val.toIntern()); |
| 2307 | if (global.toOptional() == loaded_enum.name_nav) { | 2347 | if (loaded_enum.name_nav == global.toOptional()) { |
| 2308 | _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern()); | 2348 | _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern()); |
| 2309 | } else try dwarf.genComptimeGlobal(pt, global, &decl); | 2349 | } else try dwarf.genComptimeGlobal(pt, global, &decl); |
| 2310 | }, | 2350 | }, |
| 2311 | .union_type => { | 2351 | .union_type => { |
| 2312 | const loaded_union = ip.loadUnionType(nav_val.toIntern()); | 2352 | const loaded_union = ip.loadUnionType(nav_val.toIntern()); |
| 2313 | if (global.toOptional() == loaded_union.name_nav) { | 2353 | if (loaded_union.name_nav == global.toOptional()) { |
| 2314 | _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern()); | 2354 | _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern()); |
| 2315 | } else try dwarf.genComptimeGlobal(pt, global, &decl); | 2355 | } else try dwarf.genComptimeGlobal(pt, global, &decl); |
| 2316 | }, | 2356 | }, |
| 2317 | .opaque_type => { | 2357 | .opaque_type => { |
| 2318 | const loaded_opaque = ip.loadOpaqueType(nav_val.toIntern()); | 2358 | const loaded_opaque = ip.loadOpaqueType(nav_val.toIntern()); |
| 2319 | if (global.toOptional() == loaded_opaque.name_nav) { | 2359 | if (loaded_opaque.name_nav == global.toOptional()) { |
| 2320 | _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern()); | 2360 | _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern()); |
| 2321 | } else try dwarf.genComptimeGlobal(pt, global, &decl); | 2361 | } else try dwarf.genComptimeGlobal(pt, global, &decl); |
| 2322 | }, | 2362 | }, |
| 2323 | .@"extern" => unreachable, | 2363 | .@"extern" => unreachable, |
| 2324 | .func => |func| if (func.owner_nav == global and func.generic_owner == .none) { | 2364 | .func => |func| if (func.owner_nav == global) { |
| 2325 | _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern()); | 2365 | _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern()); |
| 2326 | } else return, | 2366 | } else try dwarf.genComptimeGlobal(pt, global, &decl), |
| 2327 | .memoized_call => unreachable, // not a value | 2367 | .memoized_call => unreachable, // not a value |
| 2328 | } | 2368 | } |
| 2329 | } | 2369 | } |
| ... | @@ -2490,14 +2530,14 @@ fn updateConstInner( | ... | @@ -2490,14 +2530,14 @@ fn updateConstInner( |
| 2490 | dwarf: *Dwarf, | 2530 | dwarf: *Dwarf, |
| 2491 | pt: Zcu.PerThread, | 2531 | pt: Zcu.PerThread, |
| 2492 | di_nw: *link.MappedFile.Node.Writer, | 2532 | di_nw: *link.MappedFile.Node.Writer, |
| 2493 | val: InternPool.Index, | 2533 | @"const": InternPool.Index, |
| 2494 | ) link.EmitError!void { | 2534 | ) link.EmitError!void { |
| 2495 | const zcu = pt.zcu; | 2535 | const zcu = pt.zcu; |
| 2496 | const ip = &zcu.intern_pool; | 2536 | const ip = &zcu.intern_pool; |
| 2497 | const di_w = &di_nw.interface; | 2537 | const di_w = &di_nw.interface; |
| 2498 | switch (ip.indexToKey(val)) { | 2538 | switch (ip.indexToKey(@"const")) { |
| 2499 | .int_type => |int_type| { | 2539 | .int_type => |int_type| { |
| 2500 | const ty: Type = .fromInterned(val); | 2540 | const ty: Type = .fromInterned(@"const"); |
| 2501 | try dwarf.abbrevCode(di_nw, .numeric_type); | 2541 | try dwarf.abbrevCode(di_nw, .numeric_type); |
| 2502 | var name_buf: [std.fmt.count("i{d}", .{std.math.maxInt(u16)})]u8 = undefined; | 2542 | var name_buf: [std.fmt.count("i{d}", .{std.math.maxInt(u16)})]u8 = undefined; |
| 2503 | try dwarf.strx(di_nw, std.mem.print(&name_buf, "{f}", .{ | 2543 | try dwarf.strx(di_nw, std.mem.print(&name_buf, "{f}", .{ |
| ... | @@ -2513,7 +2553,7 @@ fn updateConstInner( | ... | @@ -2513,7 +2553,7 @@ fn updateConstInner( |
| 2513 | }, | 2553 | }, |
| 2514 | .ptr_type => |ptr_type| switch (ptr_type.flags.size) { | 2554 | .ptr_type => |ptr_type| switch (ptr_type.flags.size) { |
| 2515 | .one, .many, .c => { | 2555 | .one, .many, .c => { |
| 2516 | const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)}); | 2556 | const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(pt)}); |
| 2517 | defer zcu.gpa.free(name); | 2557 | defer zcu.gpa.free(name); |
| 2518 | try dwarf.abbrevCode(di_nw, switch (ptr_type.sentinel) { | 2558 | try dwarf.abbrevCode(di_nw, switch (ptr_type.sentinel) { |
| 2519 | .none => .ptr_type, | 2559 | .none => .ptr_type, |
| ... | @@ -2547,7 +2587,7 @@ fn updateConstInner( | ... | @@ -2547,7 +2587,7 @@ fn updateConstInner( |
| 2547 | try dwarf.refType(pt, di_nw, .fromInterned(ptr_type.child)); | 2587 | try dwarf.refType(pt, di_nw, .fromInterned(ptr_type.child)); |
| 2548 | }, | 2588 | }, |
| 2549 | .slice => { | 2589 | .slice => { |
| 2550 | const ty: Type = .fromInterned(val); | 2590 | const ty: Type = .fromInterned(@"const"); |
| 2551 | const name = try zcu.gpa.print("{f}", .{ty.fmt(pt)}); | 2591 | const name = try zcu.gpa.print("{f}", .{ty.fmt(pt)}); |
| 2552 | defer zcu.gpa.free(name); | 2592 | defer zcu.gpa.free(name); |
| 2553 | try dwarf.abbrevCode(di_nw, .generated_struct_type); | 2593 | try dwarf.abbrevCode(di_nw, .generated_struct_type); |
| ... | @@ -2568,7 +2608,7 @@ fn updateConstInner( | ... | @@ -2568,7 +2608,7 @@ fn updateConstInner( |
| 2568 | }, | 2608 | }, |
| 2569 | }, | 2609 | }, |
| 2570 | .array_type => |array_type| { | 2610 | .array_type => |array_type| { |
| 2571 | const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)}); | 2611 | const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(pt)}); |
| 2572 | defer zcu.gpa.free(name); | 2612 | defer zcu.gpa.free(name); |
| 2573 | try dwarf.abbrevCode( | 2613 | try dwarf.abbrevCode( |
| 2574 | di_nw, | 2614 | di_nw, |
| ... | @@ -2584,7 +2624,7 @@ fn updateConstInner( | ... | @@ -2584,7 +2624,7 @@ fn updateConstInner( |
| 2584 | try di_w.writeUleb128(@backingInt(AbbrevCode.null)); | 2624 | try di_w.writeUleb128(@backingInt(AbbrevCode.null)); |
| 2585 | }, | 2625 | }, |
| 2586 | .vector_type => |vector_type| { | 2626 | .vector_type => |vector_type| { |
| 2587 | const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)}); | 2627 | const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(pt)}); |
| 2588 | defer zcu.gpa.free(name); | 2628 | defer zcu.gpa.free(name); |
| 2589 | try dwarf.abbrevCode(di_nw, .vector_type); | 2629 | try dwarf.abbrevCode(di_nw, .vector_type); |
| 2590 | try dwarf.strx(di_nw, name); | 2630 | try dwarf.strx(di_nw, name); |
| ... | @@ -2595,7 +2635,7 @@ fn updateConstInner( | ... | @@ -2595,7 +2635,7 @@ fn updateConstInner( |
| 2595 | try di_w.writeUleb128(@backingInt(AbbrevCode.null)); | 2635 | try di_w.writeUleb128(@backingInt(AbbrevCode.null)); |
| 2596 | }, | 2636 | }, |
| 2597 | .opt_type => |opt_child_type_index| { | 2637 | .opt_type => |opt_child_type_index| { |
| 2598 | const opt_ty: Type = .fromInterned(val); | 2638 | const opt_ty: Type = .fromInterned(@"const"); |
| 2599 | const opt_child_ty: Type = .fromInterned(opt_child_type_index); | 2639 | const opt_child_ty: Type = .fromInterned(opt_child_type_index); |
| 2600 | const opt_repr = optRepr(opt_child_ty, zcu); | 2640 | const opt_repr = optRepr(opt_child_ty, zcu); |
| 2601 | const name = try zcu.gpa.print("{f}", .{opt_ty.fmt(pt)}); | 2641 | const name = try zcu.gpa.print("{f}", .{opt_ty.fmt(pt)}); |
| ... | @@ -2668,7 +2708,7 @@ fn updateConstInner( | ... | @@ -2668,7 +2708,7 @@ fn updateConstInner( |
| 2668 | }, | 2708 | }, |
| 2669 | .anyframe_type => unreachable, | 2709 | .anyframe_type => unreachable, |
| 2670 | .error_union_type => |error_union_type| { | 2710 | .error_union_type => |error_union_type| { |
| 2671 | const eu_ty: Type = .fromInterned(val); | 2711 | const eu_ty: Type = .fromInterned(@"const"); |
| 2672 | const eu_error_set_ty: Type = .fromInterned(error_union_type.error_set_type); | 2712 | const eu_error_set_ty: Type = .fromInterned(error_union_type.error_set_type); |
| 2673 | const eu_payload_ty: Type = .fromInterned(error_union_type.payload_type); | 2713 | const eu_payload_ty: Type = .fromInterned(error_union_type.payload_type); |
| 2674 | const eu_error_set_offset, const eu_payload_offset = switch (error_union_type.payload_type) { | 2714 | const eu_error_set_offset, const eu_payload_offset = switch (error_union_type.payload_type) { |
| ... | @@ -2747,10 +2787,10 @@ fn updateConstInner( | ... | @@ -2747,10 +2787,10 @@ fn updateConstInner( |
| 2747 | .c_longdouble, | 2787 | .c_longdouble, |
| 2748 | .bool, | 2788 | .bool, |
| 2749 | => { | 2789 | => { |
| 2750 | const ty: Type = .fromInterned(val); | 2790 | const ty: Type = .fromInterned(@"const"); |
| 2751 | try dwarf.abbrevCode(di_nw, .numeric_type); | 2791 | try dwarf.abbrevCode(di_nw, .numeric_type); |
| 2752 | try dwarf.strx(di_nw, @tagName(simple_type)); | 2792 | try dwarf.strx(di_nw, @tagName(simple_type)); |
| 2753 | try di_w.writeByte(if (val == .bool_type) | 2793 | try di_w.writeByte(if (@"const" == .bool_type) |
| 2754 | DW.ATE.boolean | 2794 | DW.ATE.boolean |
| 2755 | else if (ty.isRuntimeFloat()) | 2795 | else if (ty.isRuntimeFloat()) |
| 2756 | DW.ATE.float | 2796 | DW.ATE.float |
| ... | @@ -2778,7 +2818,7 @@ fn updateConstInner( | ... | @@ -2778,7 +2818,7 @@ fn updateConstInner( |
| 2778 | .undefined, | 2818 | .undefined, |
| 2779 | .enum_literal, | 2819 | .enum_literal, |
| 2780 | => { | 2820 | => { |
| 2781 | const ty: Type = .fromInterned(val); | 2821 | const ty: Type = .fromInterned(@"const"); |
| 2782 | try dwarf.abbrevCode(di_nw, .void_type); | 2822 | try dwarf.abbrevCode(di_nw, .void_type); |
| 2783 | var name_buf: ["@TypeOf(undefined)".len]u8 = undefined; | 2823 | var name_buf: ["@TypeOf(undefined)".len]u8 = undefined; |
| 2784 | try dwarf.strx(di_nw, std.mem.print(&name_buf, "{f}", .{ | 2824 | try dwarf.strx(di_nw, std.mem.print(&name_buf, "{f}", .{ |
| ... | @@ -2793,18 +2833,18 @@ fn updateConstInner( | ... | @@ -2793,18 +2833,18 @@ fn updateConstInner( |
| 2793 | .generated_empty_enum_type); | 2833 | .generated_empty_enum_type); |
| 2794 | try dwarf.strx(di_nw, "anyerror"); | 2834 | try dwarf.strx(di_nw, "anyerror"); |
| 2795 | try dwarf.refType(pt, di_nw, try pt.intType(.unsigned, zcu.errorSetBits())); | 2835 | try dwarf.refType(pt, di_nw, try pt.intType(.unsigned, zcu.errorSetBits())); |
| 2796 | for (global_error_set_names, 1..) |name, value| { | 2836 | for (global_error_set_names, 1..) |err_name, err_value| { |
| 2797 | try dwarf.abbrevCode(di_nw, .enum_field); | 2837 | try dwarf.abbrevCode(di_nw, .enum_field); |
| 2798 | try di_w.writeUleb128(DW.FORM.udata); | 2838 | try di_w.writeUleb128(DW.FORM.udata); |
| 2799 | try di_w.writeUleb128(value); | 2839 | try di_w.writeUleb128(err_value); |
| 2800 | try dwarf.strx(di_nw, name.toSlice(ip)); | 2840 | try dwarf.strx(di_nw, err_name.toSlice(ip)); |
| 2801 | } | 2841 | } |
| 2802 | if (global_error_set_names.len > 0) try di_w.writeUleb128(@backingInt(AbbrevCode.null)); | 2842 | if (global_error_set_names.len > 0) try di_w.writeUleb128(@backingInt(AbbrevCode.null)); |
| 2803 | }, | 2843 | }, |
| 2804 | .adhoc_inferred_error_set => unreachable, | 2844 | .adhoc_inferred_error_set => unreachable, |
| 2805 | }, | 2845 | }, |
| 2806 | .tuple_type => |tuple_type| { | 2846 | .tuple_type => |tuple_type| { |
| 2807 | const ty: Type = .fromInterned(val); | 2847 | const ty: Type = .fromInterned(@"const"); |
| 2808 | const name = try zcu.gpa.print("{f}", .{ty.fmt(pt)}); | 2848 | const name = try zcu.gpa.print("{f}", .{ty.fmt(pt)}); |
| 2809 | defer zcu.gpa.free(name); | 2849 | defer zcu.gpa.free(name); |
| 2810 | if (tuple_type.types.len == 0) { | 2850 | if (tuple_type.types.len == 0) { |
| ... | @@ -2854,7 +2894,7 @@ fn updateConstInner( | ... | @@ -2854,7 +2894,7 @@ fn updateConstInner( |
| 2854 | } | 2894 | } |
| 2855 | }, | 2895 | }, |
| 2856 | .struct_type => { | 2896 | .struct_type => { |
| 2857 | const loaded_struct = ip.loadStructType(val); | 2897 | const loaded_struct = ip.loadStructType(@"const"); |
| 2858 | const src_inst = loaded_struct.zir_index.resolveFull(ip).?; | 2898 | const src_inst = loaded_struct.zir_index.resolveFull(ip).?; |
| 2859 | const zf = zcu.fileByIndex(src_inst.file); | 2899 | const zf = zcu.fileByIndex(src_inst.file); |
| 2860 | if (src_inst.inst == .main_struct_inst) { | 2900 | if (src_inst.inst == .main_struct_inst) { |
| ... | @@ -2879,7 +2919,7 @@ fn updateConstInner( | ... | @@ -2879,7 +2919,7 @@ fn updateConstInner( |
| 2879 | try dwarf.refType(pt, di_nw, .fromInterned(ip.namespacePtr( | 2919 | try dwarf.refType(pt, di_nw, .fromInterned(ip.namespacePtr( |
| 2880 | ip.namespacePtr(loaded_struct.namespace).parent.unwrap().?, | 2920 | ip.namespacePtr(loaded_struct.namespace).parent.unwrap().?, |
| 2881 | ).owner_type)); | 2921 | ).owner_type)); |
| 2882 | try dwarf.secOffset(di_nw, try dwarf.getConstDecl(pt, val), 0); | 2922 | try dwarf.secOffset(di_nw, try dwarf.getConstDecl(pt, @"const"), 0); |
| 2883 | } else if (loaded_struct.name_nav.unwrap()) |name_ni| { | 2923 | } else if (loaded_struct.name_nav.unwrap()) |name_ni| { |
| 2884 | const name_nav = ip.getNav(name_ni); | 2924 | const name_nav = ip.getNav(name_ni); |
| 2885 | const decl = zf.zir.?.getDeclaration(name_nav.srcInst(ip).resolve(ip).?); | 2925 | const decl = zf.zir.?.getDeclaration(name_nav.srcInst(ip).resolve(ip).?); |
| ... | @@ -2921,7 +2961,7 @@ fn updateConstInner( | ... | @@ -2921,7 +2961,7 @@ fn updateConstInner( |
| 2921 | } | 2961 | } |
| 2922 | switch (loaded_struct.layout) { | 2962 | switch (loaded_struct.layout) { |
| 2923 | .auto, .@"extern" => { | 2963 | .auto, .@"extern" => { |
| 2924 | const ty: Type = .fromInterned(val); | 2964 | const ty: Type = .fromInterned(@"const"); |
| 2925 | try di_w.writeUleb128(ty.abiSize(zcu)); | 2965 | try di_w.writeUleb128(ty.abiSize(zcu)); |
| 2926 | try di_w.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?); | 2966 | try di_w.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?); |
| 2927 | try dwarf.genCaptures(pt, di_nw, loaded_struct.captures); | 2967 | try dwarf.genCaptures(pt, di_nw, loaded_struct.captures); |
| ... | @@ -2997,7 +3037,7 @@ fn updateConstInner( | ... | @@ -2997,7 +3037,7 @@ fn updateConstInner( |
| 2997 | try di_w.writeUleb128(@backingInt(AbbrevCode.null)); | 3037 | try di_w.writeUleb128(@backingInt(AbbrevCode.null)); |
| 2998 | }, | 3038 | }, |
| 2999 | .union_type => { | 3039 | .union_type => { |
| 3000 | const loaded_union = ip.loadUnionType(val); | 3040 | const loaded_union = ip.loadUnionType(@"const"); |
| 3001 | const loaded_tag = ip.loadEnumType(loaded_union.enum_tag_type); | 3041 | const loaded_tag = ip.loadEnumType(loaded_union.enum_tag_type); |
| 3002 | const zfi = loaded_union.zir_index.resolveFile(ip); | 3042 | const zfi = loaded_union.zir_index.resolveFile(ip); |
| 3003 | const zf = zcu.fileByIndex(zfi); | 3043 | const zf = zcu.fileByIndex(zfi); |
| ... | @@ -3013,7 +3053,7 @@ fn updateConstInner( | ... | @@ -3013,7 +3053,7 @@ fn updateConstInner( |
| 3013 | try dwarf.refType(pt, di_nw, .fromInterned(ip.namespacePtr( | 3053 | try dwarf.refType(pt, di_nw, .fromInterned(ip.namespacePtr( |
| 3014 | ip.namespacePtr(loaded_union.namespace).parent.unwrap().?, | 3054 | ip.namespacePtr(loaded_union.namespace).parent.unwrap().?, |
| 3015 | ).owner_type)); | 3055 | ).owner_type)); |
| 3016 | try dwarf.secOffset(di_nw, try dwarf.getConstDecl(pt, val), 0); | 3056 | try dwarf.secOffset(di_nw, try dwarf.getConstDecl(pt, @"const"), 0); |
| 3017 | } else if (loaded_union.name_nav.unwrap()) |name_ni| { | 3057 | } else if (loaded_union.name_nav.unwrap()) |name_ni| { |
| 3018 | const name_nav = ip.getNav(name_ni); | 3058 | const name_nav = ip.getNav(name_ni); |
| 3019 | const decl = zf.zir.?.getDeclaration(name_nav.srcInst(ip).resolve(ip).?); | 3059 | const decl = zf.zir.?.getDeclaration(name_nav.srcInst(ip).resolve(ip).?); |
| ... | @@ -3133,7 +3173,7 @@ fn updateConstInner( | ... | @@ -3133,7 +3173,7 @@ fn updateConstInner( |
| 3133 | try di_w.writeUleb128(@backingInt(AbbrevCode.null)); | 3173 | try di_w.writeUleb128(@backingInt(AbbrevCode.null)); |
| 3134 | }, | 3174 | }, |
| 3135 | .enum_type => { | 3175 | .enum_type => { |
| 3136 | const loaded_enum = ip.loadEnumType(val); | 3176 | const loaded_enum = ip.loadEnumType(@"const"); |
| 3137 | switch (loaded_enum.owner_union) { | 3177 | switch (loaded_enum.owner_union) { |
| 3138 | .none => { | 3178 | .none => { |
| 3139 | const zfi = loaded_enum.zir_index.unwrap().?.resolveFile(ip); | 3179 | const zfi = loaded_enum.zir_index.unwrap().?.resolveFile(ip); |
| ... | @@ -3148,7 +3188,7 @@ fn updateConstInner( | ... | @@ -3148,7 +3188,7 @@ fn updateConstInner( |
| 3148 | try dwarf.refType(pt, di_nw, .fromInterned(ip.namespacePtr( | 3188 | try dwarf.refType(pt, di_nw, .fromInterned(ip.namespacePtr( |
| 3149 | ip.namespacePtr(loaded_enum.namespace).parent.unwrap().?, | 3189 | ip.namespacePtr(loaded_enum.namespace).parent.unwrap().?, |
| 3150 | ).owner_type)); | 3190 | ).owner_type)); |
| 3151 | try dwarf.secOffset(di_nw, try dwarf.getConstDecl(pt, val), 0); | 3191 | try dwarf.secOffset(di_nw, try dwarf.getConstDecl(pt, @"const"), 0); |
| 3152 | } else if (loaded_enum.name_nav.unwrap()) |name_ni| { | 3192 | } else if (loaded_enum.name_nav.unwrap()) |name_ni| { |
| 3153 | const name_nav = ip.getNav(name_ni); | 3193 | const name_nav = ip.getNav(name_ni); |
| 3154 | const decl = zir.getDeclaration(name_nav.srcInst(ip).resolve(ip).?); | 3194 | const decl = zir.getDeclaration(name_nav.srcInst(ip).resolve(ip).?); |
| ... | @@ -3198,11 +3238,11 @@ fn updateConstInner( | ... | @@ -3198,11 +3238,11 @@ fn updateConstInner( |
| 3198 | try di_w.writeUleb128(@backingInt(AbbrevCode.null)); | 3238 | try di_w.writeUleb128(@backingInt(AbbrevCode.null)); |
| 3199 | }, | 3239 | }, |
| 3200 | // no defined size, so lowered the same as incomplete struct types | 3240 | // no defined size, so lowered the same as incomplete struct types |
| 3201 | .opaque_type => return dwarf.updateConstIncompleteInner(pt, di_nw, val), | 3241 | .opaque_type => return dwarf.updateConstIncompleteInner(pt, di_nw, @"const"), |
| 3202 | .spirv_type => unreachable, | 3242 | .spirv_type => unreachable, |
| 3203 | .func_type => |func_type| { | 3243 | .func_type => |func_type| { |
| 3204 | const is_empty = func_type.param_types.len == 0 and !func_type.is_var_args; | 3244 | const is_empty = func_type.param_types.len == 0 and !func_type.is_var_args; |
| 3205 | const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)}); | 3245 | const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(pt)}); |
| 3206 | defer zcu.gpa.free(name); | 3246 | defer zcu.gpa.free(name); |
| 3207 | try dwarf.abbrevCode(di_nw, if (is_empty) .empty_func_type else .func_type); | 3247 | try dwarf.abbrevCode(di_nw, if (is_empty) .empty_func_type else .func_type); |
| 3208 | try dwarf.strx(di_nw, name); | 3248 | try dwarf.strx(di_nw, name); |
| ... | @@ -3287,7 +3327,7 @@ fn updateConstInner( | ... | @@ -3287,7 +3327,7 @@ fn updateConstInner( |
| 3287 | if (!is_empty) try di_w.writeUleb128(@backingInt(AbbrevCode.null)); | 3327 | if (!is_empty) try di_w.writeUleb128(@backingInt(AbbrevCode.null)); |
| 3288 | }, | 3328 | }, |
| 3289 | .error_set_type => |error_set_type| { | 3329 | .error_set_type => |error_set_type| { |
| 3290 | const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)}); | 3330 | const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(pt)}); |
| 3291 | defer zcu.gpa.free(name); | 3331 | defer zcu.gpa.free(name); |
| 3292 | try dwarf.abbrevCode( | 3332 | try dwarf.abbrevCode( |
| 3293 | di_nw, | 3333 | di_nw, |
| ... | @@ -3305,7 +3345,7 @@ fn updateConstInner( | ... | @@ -3305,7 +3345,7 @@ fn updateConstInner( |
| 3305 | if (error_set_type.names.len > 0) try di_w.writeUleb128(@backingInt(AbbrevCode.null)); | 3345 | if (error_set_type.names.len > 0) try di_w.writeUleb128(@backingInt(AbbrevCode.null)); |
| 3306 | }, | 3346 | }, |
| 3307 | .inferred_error_set_type => |func| { | 3347 | .inferred_error_set_type => |func| { |
| 3308 | const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)}); | 3348 | const name = try zcu.gpa.print("{f}", .{Type.fromInterned(@"const").fmt(pt)}); |
| 3309 | defer zcu.gpa.free(name); | 3349 | defer zcu.gpa.free(name); |
| 3310 | try dwarf.abbrevCode(di_nw, .inferred_error_set_type); | 3350 | try dwarf.abbrevCode(di_nw, .inferred_error_set_type); |
| 3311 | try dwarf.strx(di_nw, name); | 3351 | try dwarf.strx(di_nw, name); |
| ... | @@ -3343,14 +3383,26 @@ fn updateConstInner( | ... | @@ -3343,14 +3383,26 @@ fn updateConstInner( |
| 3343 | const inst_info = nav.srcInst(ip).resolveFull(ip).?; | 3383 | const inst_info = nav.srcInst(ip).resolveFull(ip).?; |
| 3344 | const zir = &zcu.fileByIndex(inst_info.file).zir.?; | 3384 | const zir = &zcu.fileByIndex(inst_info.file).zir.?; |
| 3345 | const decl = zir.getDeclaration(inst_info.inst); | 3385 | const decl = zir.getDeclaration(inst_info.inst); |
| 3346 | const empty = func_type.param_types.len == 0 and !func_type.is_var_args; | 3386 | const is_empty = func_type.param_types.len == 0 and !func_type.is_var_args; |
| 3347 | const parent_ty: Type = .fromInterned(ip.namespacePtr(nav.analysis.?.namespace).owner_type); | 3387 | const parent_ty: Type = .fromInterned(ip.namespacePtr(nav.analysis.?.namespace).owner_type); |
| 3348 | try dwarf.abbrevCode(di_nw, if (empty) .decl_empty_func_generic else .decl_func_generic); | 3388 | if (func.generic_owner != .none or parent_ty.getCaptures(zcu).len > 0) { |
| 3349 | try dwarf.refType(pt, di_nw, parent_ty); | 3389 | try dwarf.abbrevCode( |
| 3350 | try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian); | 3390 | di_nw, |
| 3351 | try di_w.writeUleb128(decl.src_column + 1); | 3391 | if (is_empty) .decl_instance_empty_func_generic else .decl_instance_func_generic, |
| 3352 | try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private); | 3392 | ); |
| 3353 | try dwarf.strx(di_nw, nav.name.toSlice(ip)); | 3393 | try dwarf.refType(pt, di_nw, parent_ty); |
| | 3394 | try dwarf.secOffset(di_nw, try dwarf.getConstDecl(pt, @"const"), 0); |
| | 3395 | } else { |
| | 3396 | try dwarf.abbrevCode( |
| | 3397 | di_nw, |
| | 3398 | if (is_empty) .decl_empty_func_generic else .decl_func_generic, |
| | 3399 | ); |
| | 3400 | try dwarf.refType(pt, di_nw, parent_ty); |
| | 3401 | try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian); |
| | 3402 | try di_w.writeUleb128(decl.src_column + 1); |
| | 3403 | try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private); |
| | 3404 | try dwarf.strx(di_nw, nav.name.toSlice(ip)); |
| | 3405 | } |
| 3354 | try dwarf.refType(pt, di_nw, .fromInterned(func_type.return_type)); | 3406 | try dwarf.refType(pt, di_nw, .fromInterned(func_type.return_type)); |
| 3355 | for ( | 3407 | for ( |
| 3356 | zir.getParamBody(func.zir_body_inst.resolve(ip).?)[0..func_type.param_types.len], | 3408 | zir.getParamBody(func.zir_body_inst.resolve(ip).?)[0..func_type.param_types.len], |
| ... | @@ -3366,7 +3418,7 @@ fn updateConstInner( | ... | @@ -3366,7 +3418,7 @@ fn updateConstInner( |
| 3366 | try dwarf.refType(pt, di_nw, .fromInterned(param_ty)); | 3418 | try dwarf.refType(pt, di_nw, .fromInterned(param_ty)); |
| 3367 | } | 3419 | } |
| 3368 | if (func_type.is_var_args) try dwarf.abbrevCode(di_nw, .is_var_args); | 3420 | if (func_type.is_var_args) try dwarf.abbrevCode(di_nw, .is_var_args); |
| 3369 | if (!empty) try di_w.writeUleb128(@backingInt(AbbrevCode.null)); | 3421 | if (!is_empty) try di_w.writeUleb128(@backingInt(AbbrevCode.null)); |
| 3370 | }, | 3422 | }, |
| 3371 | .int => |int| { | 3423 | .int => |int| { |
| 3372 | var big_int_space: Value.BigIntSpace = undefined; | 3424 | var big_int_space: Value.BigIntSpace = undefined; |
| ... | @@ -3375,7 +3427,7 @@ fn updateConstInner( | ... | @@ -3375,7 +3427,7 @@ fn updateConstInner( |
| 3375 | try dwarf.bigIntConstValue( | 3427 | try dwarf.bigIntConstValue( |
| 3376 | di_w, | 3428 | di_w, |
| 3377 | .fromInterned(int.ty), | 3429 | .fromInterned(int.ty), |
| 3378 | Value.fromInterned(val).toBigInt(&big_int_space, zcu), | 3430 | Value.fromInterned(@"const").toBigInt(&big_int_space, zcu), |
| 3379 | ); | 3431 | ); |
| 3380 | }, | 3432 | }, |
| 3381 | .bitpack => |bitpack| { | 3433 | .bitpack => |bitpack| { |
| ... | @@ -3461,7 +3513,7 @@ fn updateConstInner( | ... | @@ -3461,7 +3513,7 @@ fn updateConstInner( |
| 3461 | try dwarf.bigIntConstValue( | 3513 | try dwarf.bigIntConstValue( |
| 3462 | di_w, | 3514 | di_w, |
| 3463 | .fromInterned(int.ty), | 3515 | .fromInterned(int.ty), |
| 3464 | Value.fromInterned(val).toBigInt(&big_int_space, zcu), | 3516 | Value.fromInterned(@"const").toBigInt(&big_int_space, zcu), |
| 3465 | ); | 3517 | ); |
| 3466 | }, | 3518 | }, |
| 3467 | .float => |float| { | 3519 | .float => |float| { |
| ... | @@ -3638,7 +3690,7 @@ fn updateConstInner( | ... | @@ -3638,7 +3690,7 @@ fn updateConstInner( |
| 3638 | switch (optRepr(opt_child_ty, zcu)) { | 3690 | switch (optRepr(opt_child_ty, zcu)) { |
| 3639 | .opv_null => try di_w.writeUleb128(0), | 3691 | .opv_null => try di_w.writeUleb128(0), |
| 3640 | .unpacked => try dwarf.blockConst(pt, di_nw, .makeBool(opt.val != .none)), | 3692 | .unpacked => try dwarf.blockConst(pt, di_nw, .makeBool(opt.val != .none)), |
| 3641 | .error_set, .pointer => try dwarf.blockConst(pt, di_nw, .fromInterned(val)), | 3693 | .error_set, .pointer => try dwarf.blockConst(pt, di_nw, .fromInterned(@"const")), |
| 3642 | } | 3694 | } |
| 3643 | } | 3695 | } |
| 3644 | if (opt.val != .none) child_field: { | 3696 | if (opt.val != .none) child_field: { |
| ... | @@ -4249,6 +4301,24 @@ fn genDeclInner( | ... | @@ -4249,6 +4301,24 @@ fn genDeclInner( |
| 4249 | loaded_opaque.namespace, | 4301 | loaded_opaque.namespace, |
| 4250 | }; | 4302 | }; |
| 4251 | }, | 4303 | }, |
| | 4304 | .func => |func| { |
| | 4305 | const owner_nav = ip.getNav(switch (func.generic_owner) { |
| | 4306 | else => |generic_owner| zcu.funcInfo(generic_owner).owner_nav, |
| | 4307 | .none => func.owner_nav, |
| | 4308 | }); |
| | 4309 | const inst_info = owner_nav.srcInst(ip).resolveFull(ip).?; |
| | 4310 | const decl = zcu.fileByIndex(inst_info.file).zir.?.getDeclaration(inst_info.inst); |
| | 4311 | const parent_ni = try dwarf.getConstDecl(pt, ip.namespacePtr( |
| | 4312 | owner_nav.analysis.?.namespace, |
| | 4313 | ).owner_type); |
| | 4314 | try dwarf.abbrevCode(di_nw, .decl_specification_func); |
| | 4315 | try dwarf.secOffset(di_nw, parent_ni, 0); |
| | 4316 | try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian); |
| | 4317 | try di_w.writeUleb128(decl.src_column + 1); |
| | 4318 | try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private); |
| | 4319 | try dwarf.strx(di_nw, owner_nav.name.toSlice(ip)); |
| | 4320 | break :done; |
| | 4321 | }, |
| 4252 | }; | 4322 | }; |
| 4253 | const zir = &zf.zir.?; | 4323 | const zir = &zf.zir.?; |
| 4254 | if (maybe_name_nav.unwrap()) |name_ni| { | 4324 | if (maybe_name_nav.unwrap()) |name_ni| { |