authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-06-29 04:16:47+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-07-04 21:01:41+01:00
log5f03c025058ddda09bfb3eac283bb88d30ad38cc
tree6279872cfa6a45d10bee6dd6658e71409798eb5c
parent7e552dc1e9a8388f71cc32083deb9dd848e79808
signaturelock-open Commit is signed but in an unrecognized format.

Zcu: key compile errors on `AnalUnit` where appropriate

This change seeks to more appropriately model the way semantic analysis works by drawing a more clear line between errors emitted by analyzing a `Decl` (in future a `Cau`) and errors emitted by analyzing a runtime function. This does change a few compile errors surrounding compile logs by adding more "also here" notes. The new notes are more technically correct, but perhaps not so helpful. They're not doing enough harm for me to put extensive thought into this for now.

12 files changed, 130 insertions(+), 120 deletions(-)

src/Compilation.zig+70-58
......@@ -2831,11 +2831,11 @@ pub fn totalErrorCount(comp: *Compilation) u32 {
28312831 }
28322832 }
28332833
2834 if (comp.module) |module| {
2835 total += module.failed_exports.count();
2836 total += module.failed_embed_files.count();
2834 if (comp.module) |zcu| {
2835 total += zcu.failed_exports.count();
2836 total += zcu.failed_embed_files.count();
28372837
2838 for (module.failed_files.keys(), module.failed_files.values()) |file, error_msg| {
2838 for (zcu.failed_files.keys(), zcu.failed_files.values()) |file, error_msg| {
28392839 if (error_msg) |_| {
28402840 total += 1;
28412841 } else {
......@@ -2851,23 +2851,27 @@ pub fn totalErrorCount(comp: *Compilation) u32 {
28512851 // When a parse error is introduced, we keep all the semantic analysis for
28522852 // the previous parse success, including compile errors, but we cannot
28532853 // emit them until the file succeeds parsing.
2854 for (module.failed_decls.keys()) |key| {
2855 if (module.declFileScope(key).okToReportErrors()) {
2854 for (zcu.failed_analysis.keys()) |key| {
2855 const decl_index = switch (key.unwrap()) {
2856 .decl => |d| d,
2857 .func => |ip_index| zcu.funcInfo(ip_index).owner_decl,
2858 };
2859 if (zcu.declFileScope(decl_index).okToReportErrors()) {
28562860 total += 1;
2857 if (module.cimport_errors.get(key)) |errors| {
2861 if (zcu.cimport_errors.get(key)) |errors| {
28582862 total += errors.errorMessageCount();
28592863 }
28602864 }
28612865 }
2862 if (module.emit_h) |emit_h| {
2866 if (zcu.emit_h) |emit_h| {
28632867 for (emit_h.failed_decls.keys()) |key| {
2864 if (module.declFileScope(key).okToReportErrors()) {
2868 if (zcu.declFileScope(key).okToReportErrors()) {
28652869 total += 1;
28662870 }
28672871 }
28682872 }
28692873
2870 if (module.global_error_set.entries.len - 1 > module.error_limit) {
2874 if (zcu.global_error_set.entries.len - 1 > zcu.error_limit) {
28712875 total += 1;
28722876 }
28732877 }
......@@ -2882,8 +2886,8 @@ pub fn totalErrorCount(comp: *Compilation) u32 {
28822886
28832887 // Compile log errors only count if there are no other errors.
28842888 if (total == 0) {
2885 if (comp.module) |module| {
2886 total += @intFromBool(module.compile_log_decls.count() != 0);
2889 if (comp.module) |zcu| {
2890 total += @intFromBool(zcu.compile_log_sources.count() != 0);
28872891 }
28882892 }
28892893
......@@ -2934,10 +2938,10 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
29342938 .msg = try bundle.addString("memory allocation failure"),
29352939 });
29362940 }
2937 if (comp.module) |module| {
2938 for (module.failed_files.keys(), module.failed_files.values()) |file, error_msg| {
2941 if (comp.module) |zcu| {
2942 for (zcu.failed_files.keys(), zcu.failed_files.values()) |file, error_msg| {
29392943 if (error_msg) |msg| {
2940 try addModuleErrorMsg(module, &bundle, msg.*);
2944 try addModuleErrorMsg(zcu, &bundle, msg.*);
29412945 } else {
29422946 // Must be ZIR errors. Note that this may include AST errors.
29432947 // addZirErrorMessages asserts that the tree is loaded.
......@@ -2945,54 +2949,59 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
29452949 try addZirErrorMessages(&bundle, file);
29462950 }
29472951 }
2948 for (module.failed_embed_files.values()) |error_msg| {
2949 try addModuleErrorMsg(module, &bundle, error_msg.*);
2952 for (zcu.failed_embed_files.values()) |error_msg| {
2953 try addModuleErrorMsg(zcu, &bundle, error_msg.*);
29502954 }
2951 for (module.failed_decls.keys(), module.failed_decls.values()) |decl_index, error_msg| {
2955 for (zcu.failed_analysis.keys(), zcu.failed_analysis.values()) |anal_unit, error_msg| {
2956 const decl_index = switch (anal_unit.unwrap()) {
2957 .decl => |d| d,
2958 .func => |ip_index| zcu.funcInfo(ip_index).owner_decl,
2959 };
2960
29522961 // Skip errors for Decls within files that had a parse failure.
29532962 // We'll try again once parsing succeeds.
2954 if (module.declFileScope(decl_index).okToReportErrors()) {
2955 try addModuleErrorMsg(module, &bundle, error_msg.*);
2956 if (module.cimport_errors.get(decl_index)) |errors| {
2957 for (errors.getMessages()) |err_msg_index| {
2958 const err_msg = errors.getErrorMessage(err_msg_index);
2959 try bundle.addRootErrorMessage(.{
2960 .msg = try bundle.addString(errors.nullTerminatedString(err_msg.msg)),
2961 .src_loc = if (err_msg.src_loc != .none) blk: {
2962 const src_loc = errors.getSourceLocation(err_msg.src_loc);
2963 break :blk try bundle.addSourceLocation(.{
2964 .src_path = try bundle.addString(errors.nullTerminatedString(src_loc.src_path)),
2965 .span_start = src_loc.span_start,
2966 .span_main = src_loc.span_main,
2967 .span_end = src_loc.span_end,
2968 .line = src_loc.line,
2969 .column = src_loc.column,
2970 .source_line = if (src_loc.source_line != 0) try bundle.addString(errors.nullTerminatedString(src_loc.source_line)) else 0,
2971 });
2972 } else .none,
2973 });
2974 }
2963 if (!zcu.declFileScope(decl_index).okToReportErrors()) continue;
2964
2965 try addModuleErrorMsg(zcu, &bundle, error_msg.*);
2966 if (zcu.cimport_errors.get(anal_unit)) |errors| {
2967 for (errors.getMessages()) |err_msg_index| {
2968 const err_msg = errors.getErrorMessage(err_msg_index);
2969 try bundle.addRootErrorMessage(.{
2970 .msg = try bundle.addString(errors.nullTerminatedString(err_msg.msg)),
2971 .src_loc = if (err_msg.src_loc != .none) blk: {
2972 const src_loc = errors.getSourceLocation(err_msg.src_loc);
2973 break :blk try bundle.addSourceLocation(.{
2974 .src_path = try bundle.addString(errors.nullTerminatedString(src_loc.src_path)),
2975 .span_start = src_loc.span_start,
2976 .span_main = src_loc.span_main,
2977 .span_end = src_loc.span_end,
2978 .line = src_loc.line,
2979 .column = src_loc.column,
2980 .source_line = if (src_loc.source_line != 0) try bundle.addString(errors.nullTerminatedString(src_loc.source_line)) else 0,
2981 });
2982 } else .none,
2983 });
29752984 }
29762985 }
29772986 }
2978 if (module.emit_h) |emit_h| {
2987 if (zcu.emit_h) |emit_h| {
29792988 for (emit_h.failed_decls.keys(), emit_h.failed_decls.values()) |decl_index, error_msg| {
29802989 // Skip errors for Decls within files that had a parse failure.
29812990 // We'll try again once parsing succeeds.
2982 if (module.declFileScope(decl_index).okToReportErrors()) {
2983 try addModuleErrorMsg(module, &bundle, error_msg.*);
2991 if (zcu.declFileScope(decl_index).okToReportErrors()) {
2992 try addModuleErrorMsg(zcu, &bundle, error_msg.*);
29842993 }
29852994 }
29862995 }
2987 for (module.failed_exports.values()) |value| {
2988 try addModuleErrorMsg(module, &bundle, value.*);
2996 for (zcu.failed_exports.values()) |value| {
2997 try addModuleErrorMsg(zcu, &bundle, value.*);
29892998 }
29902999
2991 const actual_error_count = module.global_error_set.entries.len - 1;
2992 if (actual_error_count > module.error_limit) {
3000 const actual_error_count = zcu.global_error_set.entries.len - 1;
3001 if (actual_error_count > zcu.error_limit) {
29933002 try bundle.addRootErrorMessage(.{
2994 .msg = try bundle.printString("module used more errors than possible: used {d}, max {d}", .{
2995 actual_error_count, module.error_limit,
3003 .msg = try bundle.printString("ZCU used more errors than possible: used {d}, max {d}", .{
3004 actual_error_count, zcu.error_limit,
29963005 }),
29973006 .notes_len = 1,
29983007 });
......@@ -3041,14 +3050,14 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
30413050 }
30423051
30433052 if (comp.module) |zcu| {
3044 if (bundle.root_list.items.len == 0 and zcu.compile_log_decls.count() != 0) {
3045 const values = zcu.compile_log_decls.values();
3053 if (bundle.root_list.items.len == 0 and zcu.compile_log_sources.count() != 0) {
3054 const values = zcu.compile_log_sources.values();
30463055 // First one will be the error; subsequent ones will be notes.
30473056 const src_loc = values[0].src().upgrade(zcu);
30483057 const err_msg: Module.ErrorMsg = .{
30493058 .src_loc = src_loc,
30503059 .msg = "found compile log statement",
3051 .notes = try gpa.alloc(Module.ErrorMsg, zcu.compile_log_decls.count() - 1),
3060 .notes = try gpa.alloc(Module.ErrorMsg, zcu.compile_log_sources.count() - 1),
30523061 };
30533062 defer gpa.free(err_msg.notes);
30543063
......@@ -3486,13 +3495,16 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !vo
34863495 const decl = module.declPtr(decl_index);
34873496 const lf = comp.bin_file.?;
34883497 lf.updateDeclLineNumber(module, decl_index) catch |err| {
3489 try module.failed_decls.ensureUnusedCapacity(gpa, 1);
3490 module.failed_decls.putAssumeCapacityNoClobber(decl_index, try Module.ErrorMsg.create(
3491 gpa,
3492 decl.navSrcLoc(module).upgrade(module),
3493 "unable to update line number: {s}",
3494 .{@errorName(err)},
3495 ));
3498 try module.failed_analysis.ensureUnusedCapacity(gpa, 1);
3499 module.failed_analysis.putAssumeCapacityNoClobber(
3500 InternPool.AnalUnit.wrap(.{ .decl = decl_index }),
3501 try Module.ErrorMsg.create(
3502 gpa,
3503 decl.navSrcLoc(module).upgrade(module),
3504 "unable to update line number: {s}",
3505 .{@errorName(err)},
3506 ),
3507 );
34963508 decl.analysis = .codegen_failure;
34973509 try module.retryable_failures.append(gpa, InternPool.AnalUnit.wrap(.{ .decl = decl_index }));
34983510 };
src/Sema.zig+14-13
......@@ -2486,7 +2486,7 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error
24862486 crash_report.compilerPanic("unexpected compile error occurred", null, null);
24872487 }
24882488
2489 try mod.failed_decls.ensureUnusedCapacity(gpa, 1);
2489 try mod.failed_analysis.ensureUnusedCapacity(gpa, 1);
24902490 try mod.failed_files.ensureUnusedCapacity(gpa, 1);
24912491
24922492 if (block) |start_block| {
......@@ -2504,7 +2504,7 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error
25042504 const max_references = refs: {
25052505 if (mod.comp.reference_trace) |num| break :refs num;
25062506 // Do not add multiple traces without explicit request.
2507 if (mod.failed_decls.count() > 0) break :ref;
2507 if (mod.failed_analysis.count() > 0) break :ref;
25082508 break :refs default_reference_trace_len;
25092509 };
25102510
......@@ -2544,7 +2544,7 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error
25442544 if (sema.func_index != .none) {
25452545 ip.funcAnalysis(sema.func_index).state = .sema_failure;
25462546 }
2547 const gop = mod.failed_decls.getOrPutAssumeCapacity(sema.owner_decl_index);
2547 const gop = mod.failed_analysis.getOrPutAssumeCapacity(sema.ownerUnit());
25482548 if (gop.found_existing) {
25492549 // If there are multiple errors for the same Decl, prefer the first one added.
25502550 sema.err = null;
......@@ -5823,11 +5823,7 @@ fn zirCompileLog(
58235823 }
58245824 try writer.print("\n", .{});
58255825
5826 const decl_index = if (sema.func_index != .none)
5827 mod.funcOwnerDeclIndex(sema.func_index)
5828 else
5829 sema.owner_decl_index;
5830 const gop = try mod.compile_log_decls.getOrPut(sema.gpa, decl_index);
5826 const gop = try mod.compile_log_sources.getOrPut(sema.gpa, sema.ownerUnit());
58315827 if (!gop.found_existing) gop.value_ptr.* = .{
58325828 .base_node_inst = block.src_base_inst,
58335829 .node_offset = src_node,
......@@ -5980,7 +5976,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
59805976 if (!comp.config.link_libc)
59815977 try sema.errNote(src, msg, "libc headers not available; compilation does not link against libc", .{});
59825978
5983 const gop = try mod.cimport_errors.getOrPut(gpa, sema.owner_decl_index);
5979 const gop = try mod.cimport_errors.getOrPut(gpa, sema.ownerUnit());
59845980 if (!gop.found_existing) {
59855981 gop.value_ptr.* = c_import_res.errors;
59865982 c_import_res.errors = std.zig.ErrorBundle.empty;
......@@ -38487,10 +38483,7 @@ pub fn flushExports(sema: *Sema) !void {
3848738483 const zcu = sema.mod;
3848838484 const gpa = zcu.gpa;
3848938485
38490 const unit: AnalUnit = if (sema.owner_func_index != .none)
38491 AnalUnit.wrap(.{ .func = sema.owner_func_index })
38492 else
38493 AnalUnit.wrap(.{ .decl = sema.owner_decl_index });
38486 const unit = sema.ownerUnit();
3849438487
3849538488 // There may be existing exports. For instance, a struct may export
3849638489 // things during both field type resolution and field default resolution.
......@@ -38524,6 +38517,14 @@ pub fn flushExports(sema: *Sema) !void {
3852438517 }
3852538518}
3852638519
38520pub fn ownerUnit(sema: Sema) AnalUnit {
38521 if (sema.owner_func_index != .none) {
38522 return AnalUnit.wrap(.{ .func = sema.owner_func_index });
38523 } else {
38524 return AnalUnit.wrap(.{ .decl = sema.owner_decl_index });
38525 }
38526}
38527
3852738528pub const bitCastVal = @import("Sema/bitcast.zig").bitCast;
3852838529pub const bitCastSpliceVal = @import("Sema/bitcast.zig").bitCastSplice;
3852938530
src/Zcu.zig+21-31
......@@ -108,15 +108,11 @@ embed_table: std.StringArrayHashMapUnmanaged(*EmbedFile) = .{},
108108/// is not yet implemented.
109109intern_pool: InternPool = .{},
110110
111/// We optimize memory usage for a compilation with no compile errors by storing the
112/// error messages and mapping outside of `Decl`.
113/// The ErrorMsg memory is owned by the decl, using Module's general purpose allocator.
114/// Note that a Decl can succeed but the Fn it represents can fail. In this case,
115/// a Decl can have a failed_decls entry but have analysis status of success.
116failed_decls: std.AutoArrayHashMapUnmanaged(Decl.Index, *ErrorMsg) = .{},
117/// Keep track of one `@compileLog` callsite per owner Decl.
111/// The ErrorMsg memory is owned by the `AnalUnit`, using Module's general purpose allocator.
112failed_analysis: std.AutoArrayHashMapUnmanaged(AnalUnit, *ErrorMsg) = .{},
113/// Keep track of one `@compileLog` callsite per `AnalUnit`.
118114/// The value is the source location of the `@compileLog` call, convertible to a `LazySrcLoc`.
119compile_log_decls: std.AutoArrayHashMapUnmanaged(Decl.Index, extern struct {
115compile_log_sources: std.AutoArrayHashMapUnmanaged(AnalUnit, extern struct {
120116 base_node_inst: InternPool.TrackedInst.Index,
121117 node_offset: i32,
122118 pub fn src(self: @This()) LazySrcLoc {
......@@ -133,9 +129,9 @@ failed_files: std.AutoArrayHashMapUnmanaged(*File, ?*ErrorMsg) = .{},
133129failed_embed_files: std.AutoArrayHashMapUnmanaged(*EmbedFile, *ErrorMsg) = .{},
134130/// Key is index into `all_exports`.
135131failed_exports: std.AutoArrayHashMapUnmanaged(u32, *ErrorMsg) = .{},
136/// If a decl failed due to a cimport error, the corresponding Clang errors
132/// If analysis failed due to a cimport error, the corresponding Clang errors
137133/// are stored here.
138cimport_errors: std.AutoArrayHashMapUnmanaged(Decl.Index, std.zig.ErrorBundle) = .{},
134cimport_errors: std.AutoArrayHashMapUnmanaged(AnalUnit, std.zig.ErrorBundle) = .{},
139135
140136/// Key is the error name, index is the error tag value. Index 0 has a length-0 string.
141137global_error_set: GlobalErrorSet = .{},
......@@ -180,6 +176,7 @@ emit_h: ?*GlobalEmitH,
180176
181177test_functions: std.AutoArrayHashMapUnmanaged(Decl.Index, void) = .{},
182178
179/// TODO: the key here will be a `Cau.Index`.
183180global_assembly: std.AutoArrayHashMapUnmanaged(Decl.Index, []u8) = .{},
184181
185182reference_table: std.AutoHashMapUnmanaged(Decl.Index, struct {
......@@ -371,9 +368,9 @@ pub const Decl = struct {
371368 /// successfully complete semantic analysis.
372369 dependency_failure,
373370 /// Semantic analysis failure.
374 /// There will be a corresponding ErrorMsg in Zcu.failed_decls.
371 /// There will be a corresponding ErrorMsg in Zcu.failed_analysis.
375372 sema_failure,
376 /// There will be a corresponding ErrorMsg in Zcu.failed_decls.
373 /// There will be a corresponding ErrorMsg in Zcu.failed_analysis.
377374 codegen_failure,
378375 /// Sematic analysis and constant value codegen of this Decl has
379376 /// succeeded. However, the Decl may be outdated due to an in-progress
......@@ -1001,11 +998,6 @@ pub const EmbedFile = struct {
1001998/// This struct holds data necessary to construct API-facing `AllErrors.Message`.
1002999/// Its memory is managed with the general purpose allocator so that they
10031000/// can be created and destroyed in response to incremental updates.
1004/// In some cases, the File could have been inferred from where the ErrorMsg
1005/// is stored. For example, if it is stored in Module.failed_decls, then the File
1006/// would be determined by the Decl Scope. However, the data structure contains the field
1007/// anyway so that `ErrorMsg` can be reused for error notes, which may be in a different
1008/// file than the parent error message. It also simplifies processing of error messages.
10091001pub const ErrorMsg = struct {
10101002 src_loc: SrcLoc,
10111003 msg: []const u8,
......@@ -2454,8 +2446,6 @@ pub fn deinit(zcu: *Zcu) void {
24542446 for (zcu.import_table.keys()) |key| {
24552447 gpa.free(key);
24562448 }
2457 var failed_decls = zcu.failed_decls;
2458 zcu.failed_decls = .{};
24592449 for (zcu.import_table.values()) |value| {
24602450 value.destroy(zcu);
24612451 }
......@@ -2473,10 +2463,10 @@ pub fn deinit(zcu: *Zcu) void {
24732463 zcu.local_zir_cache.handle.close();
24742464 zcu.global_zir_cache.handle.close();
24752465
2476 for (failed_decls.values()) |value| {
2466 for (zcu.failed_analysis.values()) |value| {
24772467 value.destroy(gpa);
24782468 }
2479 failed_decls.deinit(gpa);
2469 zcu.failed_analysis.deinit(gpa);
24802470
24812471 if (zcu.emit_h) |emit_h| {
24822472 for (emit_h.failed_decls.values()) |value| {
......@@ -2507,7 +2497,7 @@ pub fn deinit(zcu: *Zcu) void {
25072497 }
25082498 zcu.cimport_errors.deinit(gpa);
25092499
2510 zcu.compile_log_decls.deinit(gpa);
2500 zcu.compile_log_sources.deinit(gpa);
25112501
25122502 zcu.all_exports.deinit(gpa);
25132503 zcu.free_exports.deinit(gpa);
......@@ -3508,9 +3498,9 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void {
35083498 error.GenericPoison => unreachable,
35093499 else => |e| {
35103500 decl.analysis = .sema_failure;
3511 try mod.failed_decls.ensureUnusedCapacity(mod.gpa, 1);
3501 try mod.failed_analysis.ensureUnusedCapacity(mod.gpa, 1);
35123502 try mod.retryable_failures.append(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }));
3513 mod.failed_decls.putAssumeCapacityNoClobber(decl_index, try ErrorMsg.create(
3503 mod.failed_analysis.putAssumeCapacityNoClobber(AnalUnit.wrap(.{ .decl = decl_index }), try ErrorMsg.create(
35143504 mod.gpa,
35153505 decl.navSrcLoc(mod).upgrade(mod),
35163506 "unable to analyze: {s}",
......@@ -3683,9 +3673,9 @@ pub fn ensureFuncBodyAnalyzed(zcu: *Zcu, maybe_coerced_func_index: InternPool.In
36833673 verify.verify() catch |err| switch (err) {
36843674 error.OutOfMemory => return error.OutOfMemory,
36853675 else => {
3686 try zcu.failed_decls.ensureUnusedCapacity(gpa, 1);
3687 zcu.failed_decls.putAssumeCapacityNoClobber(
3688 decl_index,
3676 try zcu.failed_analysis.ensureUnusedCapacity(gpa, 1);
3677 zcu.failed_analysis.putAssumeCapacityNoClobber(
3678 AnalUnit.wrap(.{ .decl = decl_index }),
36893679 try Module.ErrorMsg.create(
36903680 gpa,
36913681 decl.navSrcLoc(zcu).upgrade(zcu),
......@@ -3709,8 +3699,8 @@ pub fn ensureFuncBodyAnalyzed(zcu: *Zcu, maybe_coerced_func_index: InternPool.In
37093699 func.analysis(ip).state = .codegen_failure;
37103700 },
37113701 else => {
3712 try zcu.failed_decls.ensureUnusedCapacity(gpa, 1);
3713 zcu.failed_decls.putAssumeCapacityNoClobber(decl_index, try Module.ErrorMsg.create(
3702 try zcu.failed_analysis.ensureUnusedCapacity(gpa, 1);
3703 zcu.failed_analysis.putAssumeCapacityNoClobber(AnalUnit.wrap(.{ .decl = decl_index }), try Module.ErrorMsg.create(
37143704 gpa,
37153705 decl.navSrcLoc(zcu).upgrade(zcu),
37163706 "unable to codegen: {s}",
......@@ -5647,8 +5637,8 @@ pub fn linkerUpdateDecl(zcu: *Zcu, decl_index: Decl.Index) !void {
56475637 },
56485638 else => {
56495639 const gpa = zcu.gpa;
5650 try zcu.failed_decls.ensureUnusedCapacity(gpa, 1);
5651 zcu.failed_decls.putAssumeCapacityNoClobber(decl_index, try ErrorMsg.create(
5640 try zcu.failed_analysis.ensureUnusedCapacity(gpa, 1);
5641 zcu.failed_analysis.putAssumeCapacityNoClobber(AnalUnit.wrap(.{ .decl = decl_index }), try ErrorMsg.create(
56525642 gpa,
56535643 decl.navSrcLoc(zcu).upgrade(zcu),
56545644 "unable to codegen: {s}",
src/codegen/llvm.zig+2-2
......@@ -1689,7 +1689,7 @@ pub const Object = struct {
16891689 fg.genBody(air.getMainBody()) catch |err| switch (err) {
16901690 error.CodegenFail => {
16911691 decl.analysis = .codegen_failure;
1692 try zcu.failed_decls.put(zcu.gpa, decl_index, dg.err_msg.?);
1692 try zcu.failed_analysis.put(zcu.gpa, InternPool.AnalUnit.wrap(.{ .decl = decl_index }), dg.err_msg.?);
16931693 dg.err_msg = null;
16941694 return;
16951695 },
......@@ -1710,7 +1710,7 @@ pub const Object = struct {
17101710 dg.genDecl() catch |err| switch (err) {
17111711 error.CodegenFail => {
17121712 decl.analysis = .codegen_failure;
1713 try module.failed_decls.put(module.gpa, decl_index, dg.err_msg.?);
1713 try module.failed_analysis.put(module.gpa, InternPool.AnalUnit.wrap(.{ .decl = decl_index }), dg.err_msg.?);
17141714 dg.err_msg = null;
17151715 return;
17161716 },
src/codegen/spirv.zig+1-1
......@@ -218,7 +218,7 @@ pub const Object = struct {
218218
219219 decl_gen.genDecl() catch |err| switch (err) {
220220 error.CodegenFail => {
221 try mod.failed_decls.put(mod.gpa, decl_index, decl_gen.error_msg.?);
221 try mod.failed_analysis.put(mod.gpa, InternPool.AnalUnit.wrap(.{ .decl = decl_index }), decl_gen.error_msg.?);
222222 },
223223 else => |other| {
224224 // There might be an error that happened *after* self.error_msg
src/link/Coff.zig+4-3
......@@ -1155,7 +1155,7 @@ pub fn updateFunc(self: *Coff, mod: *Module, func_index: InternPool.Index, air:
11551155 .ok => code_buffer.items,
11561156 .fail => |em| {
11571157 func.analysis(&mod.intern_pool).state = .codegen_failure;
1158 try mod.failed_decls.put(mod.gpa, decl_index, em);
1158 try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
11591159 return;
11601160 },
11611161 };
......@@ -1183,7 +1183,7 @@ pub fn lowerUnnamedConst(self: *Coff, val: Value, decl_index: InternPool.DeclInd
11831183 .ok => |atom_index| atom_index,
11841184 .fail => |em| {
11851185 decl.analysis = .codegen_failure;
1186 try mod.failed_decls.put(mod.gpa, decl_index, em);
1186 try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
11871187 log.err("{s}", .{em.msg});
11881188 return error.CodegenFail;
11891189 },
......@@ -1277,7 +1277,7 @@ pub fn updateDecl(
12771277 .ok => code_buffer.items,
12781278 .fail => |em| {
12791279 decl.analysis = .codegen_failure;
1280 try mod.failed_decls.put(mod.gpa, decl_index, em);
1280 try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
12811281 return;
12821282 },
12831283 };
......@@ -2751,6 +2751,7 @@ const TableSection = @import("table_section.zig").TableSection;
27512751const StringTable = @import("StringTable.zig");
27522752const Type = @import("../type.zig").Type;
27532753const Value = @import("../Value.zig");
2754const AnalUnit = InternPool.AnalUnit;
27542755
27552756pub const base_tag: link.File.Tag = .coff;
27562757
src/link/Elf/ZigObject.zig+4-3
......@@ -1096,7 +1096,7 @@ pub fn updateFunc(
10961096 .ok => code_buffer.items,
10971097 .fail => |em| {
10981098 func.analysis(&mod.intern_pool).state = .codegen_failure;
1099 try mod.failed_decls.put(mod.gpa, decl_index, em);
1099 try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
11001100 return;
11011101 },
11021102 };
......@@ -1170,7 +1170,7 @@ pub fn updateDecl(
11701170 .ok => code_buffer.items,
11711171 .fail => |em| {
11721172 decl.analysis = .codegen_failure;
1173 try mod.failed_decls.put(mod.gpa, decl_index, em);
1173 try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
11741174 return;
11751175 },
11761176 };
......@@ -1307,7 +1307,7 @@ pub fn lowerUnnamedConst(
13071307 .ok => |sym_index| sym_index,
13081308 .fail => |em| {
13091309 decl.analysis = .codegen_failure;
1310 try mod.failed_decls.put(mod.gpa, decl_index, em);
1310 try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
13111311 log.err("{s}", .{em.msg});
13121312 return error.CodegenFail;
13131313 },
......@@ -1656,4 +1656,5 @@ const Symbol = @import("Symbol.zig");
16561656const StringTable = @import("../StringTable.zig");
16571657const Type = @import("../../type.zig").Type;
16581658const Value = @import("../../Value.zig");
1659const AnalUnit = InternPool.AnalUnit;
16591660const ZigObject = @This();
src/link/MachO/ZigObject.zig+4-3
......@@ -694,7 +694,7 @@ pub fn updateFunc(
694694 .ok => code_buffer.items,
695695 .fail => |em| {
696696 func.analysis(&mod.intern_pool).state = .codegen_failure;
697 try mod.failed_decls.put(mod.gpa, decl_index, em);
697 try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
698698 return;
699699 },
700700 };
......@@ -762,7 +762,7 @@ pub fn updateDecl(
762762 .ok => code_buffer.items,
763763 .fail => |em| {
764764 decl.analysis = .codegen_failure;
765 try mod.failed_decls.put(mod.gpa, decl_index, em);
765 try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
766766 return;
767767 },
768768 };
......@@ -1105,7 +1105,7 @@ pub fn lowerUnnamedConst(
11051105 .ok => |sym_index| sym_index,
11061106 .fail => |em| {
11071107 decl.analysis = .codegen_failure;
1108 try mod.failed_decls.put(mod.gpa, decl_index, em);
1108 try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
11091109 log.err("{s}", .{em.msg});
11101110 return error.CodegenFail;
11111111 },
......@@ -1596,4 +1596,5 @@ const Symbol = @import("Symbol.zig");
15961596const StringTable = @import("../StringTable.zig");
15971597const Type = @import("../../type.zig").Type;
15981598const Value = @import("../../Value.zig");
1599const AnalUnit = InternPool.AnalUnit;
15991600const ZigObject = @This();
src/link/Plan9.zig+4-3
......@@ -17,6 +17,7 @@ const Air = @import("../Air.zig");
1717const Liveness = @import("../Liveness.zig");
1818const Type = @import("../type.zig").Type;
1919const Value = @import("../Value.zig");
20const AnalUnit = InternPool.AnalUnit;
2021
2122const std = @import("std");
2223const builtin = @import("builtin");
......@@ -449,7 +450,7 @@ pub fn updateFunc(self: *Plan9, mod: *Module, func_index: InternPool.Index, air:
449450 .ok => try code_buffer.toOwnedSlice(),
450451 .fail => |em| {
451452 func.analysis(&mod.intern_pool).state = .codegen_failure;
452 try mod.failed_decls.put(mod.gpa, decl_index, em);
453 try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
453454 return;
454455 },
455456 };
......@@ -513,7 +514,7 @@ pub fn lowerUnnamedConst(self: *Plan9, val: Value, decl_index: InternPool.DeclIn
513514 .ok => code_buffer.items,
514515 .fail => |em| {
515516 decl.analysis = .codegen_failure;
516 try mod.failed_decls.put(mod.gpa, decl_index, em);
517 try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
517518 log.err("{s}", .{em.msg});
518519 return error.CodegenFail;
519520 },
......@@ -550,7 +551,7 @@ pub fn updateDecl(self: *Plan9, mod: *Module, decl_index: InternPool.DeclIndex)
550551 .ok => code_buffer.items,
551552 .fail => |em| {
552553 decl.analysis = .codegen_failure;
553 try mod.failed_decls.put(mod.gpa, decl_index, em);
554 try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
554555 return;
555556 },
556557 };
src/link/Wasm/ZigObject.zig+4-3
......@@ -280,7 +280,7 @@ pub fn updateDecl(
280280 .ok => code_writer.items,
281281 .fail => |em| {
282282 decl.analysis = .codegen_failure;
283 try mod.failed_decls.put(mod.gpa, decl_index, em);
283 try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
284284 return;
285285 },
286286 };
......@@ -320,7 +320,7 @@ pub fn updateFunc(
320320 .ok => code_writer.items,
321321 .fail => |em| {
322322 decl.analysis = .codegen_failure;
323 try mod.failed_decls.put(mod.gpa, decl_index, em);
323 try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
324324 return;
325325 },
326326 };
......@@ -501,7 +501,7 @@ pub fn lowerUnnamedConst(zig_object: *ZigObject, wasm_file: *Wasm, val: Value, d
501501 },
502502 .fail => |em| {
503503 decl.analysis = .codegen_failure;
504 try mod.failed_decls.put(mod.gpa, decl_index, em);
504 try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
505505 return error.CodegenFail;
506506 },
507507 }
......@@ -1255,4 +1255,5 @@ const Symbol = @import("Symbol.zig");
12551255const Type = @import("../../type.zig").Type;
12561256const Value = @import("../../Value.zig");
12571257const Wasm = @import("../Wasm.zig");
1258const AnalUnit = InternPool.AnalUnit;
12581259const ZigObject = @This();
test/cases/compile_errors/compileLog_of_tagged_enum_doesnt_crash_the_compiler.zig+1
......@@ -16,6 +16,7 @@ pub export fn entry() void {
1616// target=native
1717//
1818// :6:5: error: found compile log statement
19// :6:5: note: also here
1920//
2021// Compile Log Output:
2122// @as(tmp.Bar, .{ .X = 123 })
test/cases/compile_errors/compile_log.zig+1
......@@ -18,6 +18,7 @@ export fn baz() void {
1818//
1919// :6:5: error: found compile log statement
2020// :12:5: note: also here
21// :6:5: note: also here
2122//
2223// Compile Log Output:
2324// @as(*const [5:0]u8, "begin")