| ... | ... | @@ -3328,7 +3328,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle { |
| 3328 | 3328 | if (comp.zcu) |zcu| zcu_errors: { |
| 3329 | 3329 | for (zcu.failed_files.keys(), zcu.failed_files.values()) |file, error_msg| { |
| 3330 | 3330 | if (error_msg) |msg| { |
| 3331 | | try addModuleErrorMsg(zcu, &bundle, msg.*); |
| 3331 | try addModuleErrorMsg(zcu, &bundle, msg.*, false); |
| 3332 | 3332 | } else { |
| 3333 | 3333 | // Must be ZIR or Zoir errors. Note that this may include AST errors. |
| 3334 | 3334 | _ = try file.getTree(gpa); // Tree must be loaded. |
| ... | ... | @@ -3378,6 +3378,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle { |
| 3378 | 3378 | break :s entries.slice(); |
| 3379 | 3379 | }; |
| 3380 | 3380 | defer sorted_failed_analysis.deinit(gpa); |
| 3381 | var added_any_analysis_error = false; |
| 3381 | 3382 | for (sorted_failed_analysis.items(.key), sorted_failed_analysis.items(.value)) |anal_unit, error_msg| { |
| 3382 | 3383 | if (comp.incremental) { |
| 3383 | 3384 | const refs = try zcu.resolveReferences(); |
| ... | ... | @@ -3389,7 +3390,9 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle { |
| 3389 | 3390 | zcu.fmtAnalUnit(anal_unit), |
| 3390 | 3391 | }); |
| 3391 | 3392 | |
| 3392 | | try addModuleErrorMsg(zcu, &bundle, error_msg.*); |
| 3393 | try addModuleErrorMsg(zcu, &bundle, error_msg.*, added_any_analysis_error); |
| 3394 | added_any_analysis_error = true; |
| 3395 | |
| 3393 | 3396 | if (zcu.cimport_errors.get(anal_unit)) |errors| { |
| 3394 | 3397 | for (errors.getMessages()) |err_msg_index| { |
| 3395 | 3398 | const err_msg = errors.getErrorMessage(err_msg_index); |
| ... | ... | @@ -3412,13 +3415,13 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle { |
| 3412 | 3415 | } |
| 3413 | 3416 | } |
| 3414 | 3417 | for (zcu.failed_codegen.values()) |error_msg| { |
| 3415 | | try addModuleErrorMsg(zcu, &bundle, error_msg.*); |
| 3418 | try addModuleErrorMsg(zcu, &bundle, error_msg.*, false); |
| 3416 | 3419 | } |
| 3417 | 3420 | for (zcu.failed_types.values()) |error_msg| { |
| 3418 | | try addModuleErrorMsg(zcu, &bundle, error_msg.*); |
| 3421 | try addModuleErrorMsg(zcu, &bundle, error_msg.*, false); |
| 3419 | 3422 | } |
| 3420 | 3423 | for (zcu.failed_exports.values()) |value| { |
| 3421 | | try addModuleErrorMsg(zcu, &bundle, value.*); |
| 3424 | try addModuleErrorMsg(zcu, &bundle, value.*, false); |
| 3422 | 3425 | } |
| 3423 | 3426 | |
| 3424 | 3427 | const actual_error_count = zcu.intern_pool.global_error_set.getNamesFromMainThread().len; |
| ... | ... | @@ -3527,7 +3530,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle { |
| 3527 | 3530 | // We don't actually include the error here if `!include_compile_log_sources`. |
| 3528 | 3531 | // The sorting above was still necessary, though, to get `log_text` in the right order. |
| 3529 | 3532 | if (include_compile_log_sources) { |
| 3530 | | try addModuleErrorMsg(zcu, &bundle, messages.items[0]); |
| 3533 | try addModuleErrorMsg(zcu, &bundle, messages.items[0], false); |
| 3531 | 3534 | } |
| 3532 | 3535 | |
| 3533 | 3536 | break :compile_log_text try log_text.toOwnedSlice(gpa); |
| ... | ... | @@ -3631,10 +3634,14 @@ pub const ErrorNoteHashContext = struct { |
| 3631 | 3634 | } |
| 3632 | 3635 | }; |
| 3633 | 3636 | |
| 3637 | const default_reference_trace_len = 2; |
| 3634 | 3638 | pub fn addModuleErrorMsg( |
| 3635 | 3639 | zcu: *Zcu, |
| 3636 | 3640 | eb: *ErrorBundle.Wip, |
| 3637 | 3641 | module_err_msg: Zcu.ErrorMsg, |
| 3642 | /// If `-freference-trace` is not specified, we only want to show the one reference trace. |
| 3643 | /// So, this is whether we have already emitted an error with a reference trace. |
| 3644 | already_added_error: bool, |
| 3638 | 3645 | ) !void { |
| 3639 | 3646 | const gpa = eb.gpa; |
| 3640 | 3647 | const ip = &zcu.intern_pool; |
| ... | ... | @@ -3657,14 +3664,18 @@ pub fn addModuleErrorMsg( |
| 3657 | 3664 | var ref_traces: std.ArrayListUnmanaged(ErrorBundle.ReferenceTrace) = .empty; |
| 3658 | 3665 | defer ref_traces.deinit(gpa); |
| 3659 | 3666 | |
| 3660 | | if (module_err_msg.reference_trace_root.unwrap()) |rt_root| { |
| 3667 | rt: { |
| 3668 | const rt_root = module_err_msg.reference_trace_root.unwrap() orelse break :rt; |
| 3669 | const max_references = zcu.comp.reference_trace orelse refs: { |
| 3670 | if (already_added_error) break :rt; |
| 3671 | break :refs default_reference_trace_len; |
| 3672 | }; |
| 3673 | |
| 3661 | 3674 | const all_references = try zcu.resolveReferences(); |
| 3662 | 3675 | |
| 3663 | 3676 | var seen: std.AutoHashMapUnmanaged(InternPool.AnalUnit, void) = .empty; |
| 3664 | 3677 | defer seen.deinit(gpa); |
| 3665 | 3678 | |
| 3666 | | const max_references = zcu.comp.reference_trace orelse Sema.default_reference_trace_len; |
| 3667 | | |
| 3668 | 3679 | var referenced_by = rt_root; |
| 3669 | 3680 | while (all_references.get(referenced_by)) |maybe_ref| { |
| 3670 | 3681 | const ref = maybe_ref orelse break; |