| ... | @@ -3076,15 +3076,12 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle { | ... | @@ -3076,15 +3076,12 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle { |
| 3076 | }); | 3076 | }); |
| 3077 | } | 3077 | } |
| 3078 | | 3078 | |
| 3079 | var all_references: ?std.AutoHashMapUnmanaged(InternPool.AnalUnit, ?Zcu.ResolvedReference) = null; | | |
| 3080 | defer if (all_references) |*a| a.deinit(gpa); | | |
| 3081 | | | |
| 3082 | if (comp.zcu) |zcu| { | 3079 | if (comp.zcu) |zcu| { |
| 3083 | const ip = &zcu.intern_pool; | 3080 | const ip = &zcu.intern_pool; |
| 3084 | | 3081 | |
| 3085 | for (zcu.failed_files.keys(), zcu.failed_files.values()) |file, error_msg| { | 3082 | for (zcu.failed_files.keys(), zcu.failed_files.values()) |file, error_msg| { |
| 3086 | if (error_msg) |msg| { | 3083 | if (error_msg) |msg| { |
| 3087 | try addModuleErrorMsg(zcu, &bundle, msg.*, &all_references); | 3084 | try addModuleErrorMsg(zcu, &bundle, msg.*); |
| 3088 | } else { | 3085 | } else { |
| 3089 | // Must be ZIR errors. Note that this may include AST errors. | 3086 | // Must be ZIR errors. Note that this may include AST errors. |
| 3090 | // addZirErrorMessages asserts that the tree is loaded. | 3087 | // addZirErrorMessages asserts that the tree is loaded. |
| ... | @@ -3093,7 +3090,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle { | ... | @@ -3093,7 +3090,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle { |
| 3093 | } | 3090 | } |
| 3094 | } | 3091 | } |
| 3095 | for (zcu.failed_embed_files.values()) |error_msg| { | 3092 | for (zcu.failed_embed_files.values()) |error_msg| { |
| 3096 | try addModuleErrorMsg(zcu, &bundle, error_msg.*, &all_references); | 3093 | try addModuleErrorMsg(zcu, &bundle, error_msg.*); |
| 3097 | } | 3094 | } |
| 3098 | { | 3095 | { |
| 3099 | const SortOrder = struct { | 3096 | const SortOrder = struct { |
| ... | @@ -3136,10 +3133,8 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle { | ... | @@ -3136,10 +3133,8 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle { |
| 3136 | } | 3133 | } |
| 3137 | for (zcu.failed_analysis.keys(), zcu.failed_analysis.values()) |anal_unit, error_msg| { | 3134 | for (zcu.failed_analysis.keys(), zcu.failed_analysis.values()) |anal_unit, error_msg| { |
| 3138 | if (comp.incremental) { | 3135 | if (comp.incremental) { |
| 3139 | if (all_references == null) { | 3136 | const refs = try zcu.resolveReferences(); |
| 3140 | all_references = try zcu.resolveReferences(); | 3137 | if (!refs.contains(anal_unit)) continue; |
| 3141 | } | | |
| 3142 | if (!all_references.?.contains(anal_unit)) continue; | | |
| 3143 | } | 3138 | } |
| 3144 | | 3139 | |
| 3145 | const file_index = switch (anal_unit.unwrap()) { | 3140 | const file_index = switch (anal_unit.unwrap()) { |
| ... | @@ -3151,7 +3146,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle { | ... | @@ -3151,7 +3146,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle { |
| 3151 | // We'll try again once parsing succeeds. | 3146 | // We'll try again once parsing succeeds. |
| 3152 | if (!zcu.fileByIndex(file_index).okToReportErrors()) continue; | 3147 | if (!zcu.fileByIndex(file_index).okToReportErrors()) continue; |
| 3153 | | 3148 | |
| 3154 | try addModuleErrorMsg(zcu, &bundle, error_msg.*, &all_references); | 3149 | try addModuleErrorMsg(zcu, &bundle, error_msg.*); |
| 3155 | if (zcu.cimport_errors.get(anal_unit)) |errors| { | 3150 | if (zcu.cimport_errors.get(anal_unit)) |errors| { |
| 3156 | for (errors.getMessages()) |err_msg_index| { | 3151 | for (errors.getMessages()) |err_msg_index| { |
| 3157 | const err_msg = errors.getErrorMessage(err_msg_index); | 3152 | const err_msg = errors.getErrorMessage(err_msg_index); |
| ... | @@ -3175,10 +3170,10 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle { | ... | @@ -3175,10 +3170,10 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle { |
| 3175 | } | 3170 | } |
| 3176 | for (zcu.failed_codegen.keys(), zcu.failed_codegen.values()) |nav, error_msg| { | 3171 | for (zcu.failed_codegen.keys(), zcu.failed_codegen.values()) |nav, error_msg| { |
| 3177 | if (!zcu.navFileScope(nav).okToReportErrors()) continue; | 3172 | if (!zcu.navFileScope(nav).okToReportErrors()) continue; |
| 3178 | try addModuleErrorMsg(zcu, &bundle, error_msg.*, &all_references); | 3173 | try addModuleErrorMsg(zcu, &bundle, error_msg.*); |
| 3179 | } | 3174 | } |
| 3180 | for (zcu.failed_exports.values()) |value| { | 3175 | for (zcu.failed_exports.values()) |value| { |
| 3181 | try addModuleErrorMsg(zcu, &bundle, value.*, &all_references); | 3176 | try addModuleErrorMsg(zcu, &bundle, value.*); |
| 3182 | } | 3177 | } |
| 3183 | | 3178 | |
| 3184 | const actual_error_count = zcu.intern_pool.global_error_set.getNamesFromMainThread().len; | 3179 | const actual_error_count = zcu.intern_pool.global_error_set.getNamesFromMainThread().len; |
| ... | @@ -3252,17 +3247,15 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle { | ... | @@ -3252,17 +3247,15 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle { |
| 3252 | }; | 3247 | }; |
| 3253 | } | 3248 | } |
| 3254 | | 3249 | |
| 3255 | try addModuleErrorMsg(zcu, &bundle, err_msg, &all_references); | 3250 | try addModuleErrorMsg(zcu, &bundle, err_msg); |
| 3256 | } | 3251 | } |
| 3257 | } | 3252 | } |
| 3258 | | 3253 | |
| 3259 | if (comp.zcu) |zcu| { | 3254 | if (comp.zcu) |zcu| { |
| 3260 | if (comp.incremental and bundle.root_list.items.len == 0) { | 3255 | if (comp.incremental and bundle.root_list.items.len == 0) { |
| 3261 | const should_have_error = for (zcu.transitive_failed_analysis.keys()) |failed_unit| { | 3256 | const should_have_error = for (zcu.transitive_failed_analysis.keys()) |failed_unit| { |
| 3262 | if (all_references == null) { | 3257 | const refs = try zcu.resolveReferences(); |
| 3263 | all_references = try zcu.resolveReferences(); | 3258 | if (refs.contains(failed_unit)) break true; |
| 3264 | } | | |
| 3265 | if (all_references.?.contains(failed_unit)) break true; | | |
| 3266 | } else false; | 3259 | } else false; |
| 3267 | if (should_have_error) { | 3260 | if (should_have_error) { |
| 3268 | @panic("referenced transitive analysis errors, but none actually emitted"); | 3261 | @panic("referenced transitive analysis errors, but none actually emitted"); |
| ... | @@ -3331,14 +3324,13 @@ pub const ErrorNoteHashContext = struct { | ... | @@ -3331,14 +3324,13 @@ pub const ErrorNoteHashContext = struct { |
| 3331 | }; | 3324 | }; |
| 3332 | | 3325 | |
| 3333 | pub fn addModuleErrorMsg( | 3326 | pub fn addModuleErrorMsg( |
| 3334 | mod: *Zcu, | 3327 | zcu: *Zcu, |
| 3335 | eb: *ErrorBundle.Wip, | 3328 | eb: *ErrorBundle.Wip, |
| 3336 | module_err_msg: Zcu.ErrorMsg, | 3329 | module_err_msg: Zcu.ErrorMsg, |
| 3337 | all_references: *?std.AutoHashMapUnmanaged(InternPool.AnalUnit, ?Zcu.ResolvedReference), | | |
| 3338 | ) !void { | 3330 | ) !void { |
| 3339 | const gpa = eb.gpa; | 3331 | const gpa = eb.gpa; |
| 3340 | const ip = &mod.intern_pool; | 3332 | const ip = &zcu.intern_pool; |
| 3341 | const err_src_loc = module_err_msg.src_loc.upgrade(mod); | 3333 | const err_src_loc = module_err_msg.src_loc.upgrade(zcu); |
| 3342 | const err_source = err_src_loc.file_scope.getSource(gpa) catch |err| { | 3334 | const err_source = err_src_loc.file_scope.getSource(gpa) catch |err| { |
| 3343 | const file_path = try err_src_loc.file_scope.fullPath(gpa); | 3335 | const file_path = try err_src_loc.file_scope.fullPath(gpa); |
| 3344 | defer gpa.free(file_path); | 3336 | defer gpa.free(file_path); |
| ... | @@ -3358,22 +3350,20 @@ pub fn addModuleErrorMsg( | ... | @@ -3358,22 +3350,20 @@ pub fn addModuleErrorMsg( |
| 3358 | defer ref_traces.deinit(gpa); | 3350 | defer ref_traces.deinit(gpa); |
| 3359 | | 3351 | |
| 3360 | if (module_err_msg.reference_trace_root.unwrap()) |rt_root| { | 3352 | if (module_err_msg.reference_trace_root.unwrap()) |rt_root| { |
| 3361 | if (all_references.* == null) { | 3353 | const all_references = try zcu.resolveReferences(); |
| 3362 | all_references.* = try mod.resolveReferences(); | | |
| 3363 | } | | |
| 3364 | | 3354 | |
| 3365 | var seen: std.AutoHashMapUnmanaged(InternPool.AnalUnit, void) = .empty; | 3355 | var seen: std.AutoHashMapUnmanaged(InternPool.AnalUnit, void) = .empty; |
| 3366 | defer seen.deinit(gpa); | 3356 | defer seen.deinit(gpa); |
| 3367 | | 3357 | |
| 3368 | const max_references = mod.comp.reference_trace orelse Sema.default_reference_trace_len; | 3358 | const max_references = zcu.comp.reference_trace orelse Sema.default_reference_trace_len; |
| 3369 | | 3359 | |
| 3370 | var referenced_by = rt_root; | 3360 | var referenced_by = rt_root; |
| 3371 | while (all_references.*.?.get(referenced_by)) |maybe_ref| { | 3361 | while (all_references.get(referenced_by)) |maybe_ref| { |
| 3372 | const ref = maybe_ref orelse break; | 3362 | const ref = maybe_ref orelse break; |
| 3373 | const gop = try seen.getOrPut(gpa, ref.referencer); | 3363 | const gop = try seen.getOrPut(gpa, ref.referencer); |
| 3374 | if (gop.found_existing) break; | 3364 | if (gop.found_existing) break; |
| 3375 | if (ref_traces.items.len < max_references) { | 3365 | if (ref_traces.items.len < max_references) { |
| 3376 | const src = ref.src.upgrade(mod); | 3366 | const src = ref.src.upgrade(zcu); |
| 3377 | const source = try src.file_scope.getSource(gpa); | 3367 | const source = try src.file_scope.getSource(gpa); |
| 3378 | const span = try src.span(gpa); | 3368 | const span = try src.span(gpa); |
| 3379 | const loc = std.zig.findLineColumn(source.bytes, span.main); | 3369 | const loc = std.zig.findLineColumn(source.bytes, span.main); |
| ... | @@ -3385,7 +3375,7 @@ pub fn addModuleErrorMsg( | ... | @@ -3385,7 +3375,7 @@ pub fn addModuleErrorMsg( |
| 3385 | .type => |ty| Type.fromInterned(ty).containerTypeName(ip).toSlice(ip), | 3375 | .type => |ty| Type.fromInterned(ty).containerTypeName(ip).toSlice(ip), |
| 3386 | .none => "comptime", | 3376 | .none => "comptime", |
| 3387 | }, | 3377 | }, |
| 3388 | .func => |f| ip.getNav(mod.funcInfo(f).owner_nav).name.toSlice(ip), | 3378 | .func => |f| ip.getNav(zcu.funcInfo(f).owner_nav).name.toSlice(ip), |
| 3389 | }; | 3379 | }; |
| 3390 | try ref_traces.append(gpa, .{ | 3380 | try ref_traces.append(gpa, .{ |
| 3391 | .decl_name = try eb.addString(name), | 3381 | .decl_name = try eb.addString(name), |
| ... | @@ -3435,7 +3425,7 @@ pub fn addModuleErrorMsg( | ... | @@ -3435,7 +3425,7 @@ pub fn addModuleErrorMsg( |
| 3435 | defer notes.deinit(gpa); | 3425 | defer notes.deinit(gpa); |
| 3436 | | 3426 | |
| 3437 | for (module_err_msg.notes) |module_note| { | 3427 | for (module_err_msg.notes) |module_note| { |
| 3438 | const note_src_loc = module_note.src_loc.upgrade(mod); | 3428 | const note_src_loc = module_note.src_loc.upgrade(zcu); |
| 3439 | const source = try note_src_loc.file_scope.getSource(gpa); | 3429 | const source = try note_src_loc.file_scope.getSource(gpa); |
| 3440 | const span = try note_src_loc.span(gpa); | 3430 | const span = try note_src_loc.span(gpa); |
| 3441 | const loc = std.zig.findLineColumn(source.bytes, span.main); | 3431 | const loc = std.zig.findLineColumn(source.bytes, span.main); |
| ... | @@ -3488,13 +3478,13 @@ pub fn performAllTheWork( | ... | @@ -3488,13 +3478,13 @@ pub fn performAllTheWork( |
| 3488 | comp: *Compilation, | 3478 | comp: *Compilation, |
| 3489 | main_progress_node: std.Progress.Node, | 3479 | main_progress_node: std.Progress.Node, |
| 3490 | ) JobError!void { | 3480 | ) JobError!void { |
| 3491 | defer if (comp.zcu) |mod| { | 3481 | defer if (comp.zcu) |zcu| { |
| 3492 | mod.sema_prog_node.end(); | 3482 | zcu.sema_prog_node.end(); |
| 3493 | mod.sema_prog_node = std.Progress.Node.none; | 3483 | zcu.sema_prog_node = std.Progress.Node.none; |
| 3494 | mod.codegen_prog_node.end(); | 3484 | zcu.codegen_prog_node.end(); |
| 3495 | mod.codegen_prog_node = std.Progress.Node.none; | 3485 | zcu.codegen_prog_node = std.Progress.Node.none; |
| 3496 | | 3486 | |
| 3497 | mod.generation += 1; | 3487 | zcu.generation += 1; |
| 3498 | }; | 3488 | }; |
| 3499 | try comp.performAllTheWorkInner(main_progress_node); | 3489 | try comp.performAllTheWorkInner(main_progress_node); |
| 3500 | if (!InternPool.single_threaded) if (comp.codegen_work.job_error) |job_error| return job_error; | 3490 | if (!InternPool.single_threaded) if (comp.codegen_work.job_error) |job_error| return job_error; |