Skip to content

Commit fd62912

Browse files
committed
incremental: correctly handle losing file root struct_decl inst
1 parent f818098 commit fd62912

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/Zcu/PerThread.zig

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -545,10 +545,19 @@ pub fn updateZirRefs(pt: Zcu.PerThread) Allocator.Error!void {
545545
pub fn ensureFileAnalyzed(pt: Zcu.PerThread, file_index: Zcu.File.Index) Zcu.SemaError!void {
546546
const file_root_type = pt.zcu.fileRootType(file_index);
547547
if (file_root_type != .none) {
548-
_ = try pt.ensureTypeUpToDate(file_root_type);
549-
} else {
550-
return pt.semaFile(file_index);
548+
if (pt.ensureTypeUpToDate(file_root_type)) |_| {
549+
return;
550+
} else |err| switch (err) {
551+
error.AnalysisFail => {
552+
// The file's root `struct_decl` has, at some point, been lost, because the file failed AstGen.
553+
// Clear `file_root_type`, and try the `semaFile` call below, in case the instruction has since
554+
// been discovered under a new `TrackedInst.Index`.
555+
pt.zcu.setFileRootType(file_index, .none);
556+
},
557+
else => |e| return e,
558+
}
551559
}
560+
return pt.semaFile(file_index);
552561
}
553562

554563
/// Ensures that the state of the given `ComptimeUnit` is fully up-to-date, performing re-analysis

0 commit comments

Comments
 (0)