@@ -3102,9 +3102,10 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
3102
3102
for (zcu .failed_embed_files .values ()) | error_msg | {
3103
3103
try addModuleErrorMsg (zcu , & bundle , error_msg .* );
3104
3104
}
3105
- {
3105
+ var sorted_failed_analysis : std . AutoArrayHashMapUnmanaged ( InternPool.AnalUnit , * Zcu . ErrorMsg ). DataList . Slice = s : {
3106
3106
const SortOrder = struct {
3107
3107
zcu : * Zcu ,
3108
+ errors : []const * Zcu.ErrorMsg ,
3108
3109
err : * ? Error ,
3109
3110
3110
3111
const Error = @typeInfo (
@@ -3113,12 +3114,11 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
3113
3114
3114
3115
pub fn lessThan (ctx : @This (), lhs_index : usize , rhs_index : usize ) bool {
3115
3116
if (ctx .err .* ) | _ | return lhs_index < rhs_index ;
3116
- const errors = ctx .zcu .failed_analysis .values ();
3117
- const lhs_src_loc = errors [lhs_index ].src_loc .upgradeOrLost (ctx .zcu ) orelse {
3117
+ const lhs_src_loc = ctx .errors [lhs_index ].src_loc .upgradeOrLost (ctx .zcu ) orelse {
3118
3118
// LHS source location lost, so should never be referenced. Just sort it to the end.
3119
3119
return false ;
3120
3120
};
3121
- const rhs_src_loc = errors [rhs_index ].src_loc .upgradeOrLost (ctx .zcu ) orelse {
3121
+ const rhs_src_loc = ctx . errors [rhs_index ].src_loc .upgradeOrLost (ctx .zcu ) orelse {
3122
3122
// RHS source location lost, so should never be referenced. Just sort it to the end.
3123
3123
return true ;
3124
3124
};
@@ -3135,13 +3135,24 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
3135
3135
}).main ;
3136
3136
}
3137
3137
};
3138
+
3139
+ // We can't directly sort `zcu.failed_analysis.entries`, because that would leave the map
3140
+ // in an invalid state, and we need it intact for future incremental updates. The amount
3141
+ // of data here is only as large as the number of analysis errors, so just dupe it all.
3142
+ var entries = try zcu .failed_analysis .entries .clone (gpa );
3143
+ errdefer entries .deinit (gpa );
3144
+
3138
3145
var err : ? SortOrder.Error = null ;
3139
- // This leaves `zcu.failed_analysis` an invalid state, but we do not
3140
- // need lookups anymore anyway.
3141
- zcu .failed_analysis .entries .sort (SortOrder { .zcu = zcu , .err = & err });
3146
+ entries .sort (SortOrder {
3147
+ .zcu = zcu ,
3148
+ .errors = entries .items (.value ),
3149
+ .err = & err ,
3150
+ });
3142
3151
if (err ) | e | return e ;
3143
- }
3144
- for (zcu .failed_analysis .keys (), zcu .failed_analysis .values ()) | anal_unit , error_msg | {
3152
+ break :s entries .slice ();
3153
+ };
3154
+ defer sorted_failed_analysis .deinit (gpa );
3155
+ for (sorted_failed_analysis .items (.key ), sorted_failed_analysis .items (.value )) | anal_unit , error_msg | {
3145
3156
if (comp .incremental ) {
3146
3157
const refs = try zcu .resolveReferences ();
3147
3158
if (! refs .contains (anal_unit )) continue ;
@@ -3158,6 +3169,11 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
3158
3169
// We'll try again once parsing succeeds.
3159
3170
if (! zcu .fileByIndex (file_index ).okToReportErrors ()) continue ;
3160
3171
3172
+ std .log .scoped (.zcu ).debug ("analysis error '{s}' reported from unit '{}'" , .{
3173
+ error_msg .msg ,
3174
+ zcu .fmtAnalUnit (anal_unit ),
3175
+ });
3176
+
3161
3177
try addModuleErrorMsg (zcu , & bundle , error_msg .* );
3162
3178
if (zcu .cimport_errors .get (anal_unit )) | errors | {
3163
3179
for (errors .getMessages ()) | err_msg_index | {
0 commit comments