From fd62912787ee4f26b06ba86560e9aa605095ae04 Mon Sep 17 00:00:00 2001 From: mlugg Date: Sat, 4 Jan 2025 00:06:24 +0000 Subject: [PATCH] incremental: correctly handle losing file root `struct_decl` inst --- src/Zcu/PerThread.zig | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Zcu/PerThread.zig b/src/Zcu/PerThread.zig index 393d3ed837..c382d78efa 100644 --- a/src/Zcu/PerThread.zig +++ b/src/Zcu/PerThread.zig @@ -545,10 +545,19 @@ pub fn updateZirRefs(pt: Zcu.PerThread) Allocator.Error!void { pub fn ensureFileAnalyzed(pt: Zcu.PerThread, file_index: Zcu.File.Index) Zcu.SemaError!void { const file_root_type = pt.zcu.fileRootType(file_index); if (file_root_type != .none) { - _ = try pt.ensureTypeUpToDate(file_root_type); - } else { - return pt.semaFile(file_index); + if (pt.ensureTypeUpToDate(file_root_type)) |_| { + return; + } else |err| switch (err) { + error.AnalysisFail => { + // The file's root `struct_decl` has, at some point, been lost, because the file failed AstGen. + // Clear `file_root_type`, and try the `semaFile` call below, in case the instruction has since + // been discovered under a new `TrackedInst.Index`. + pt.zcu.setFileRootType(file_index, .none); + }, + else => |e| return e, + } } + return pt.semaFile(file_index); } /// Ensures that the state of the given `ComptimeUnit` is fully up-to-date, performing re-analysis