aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-04-07 20:36:01 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-04-07 20:36:01 -0700
commit12087d4cbaab39acadc29716e92765c92b92e28c (patch)
treebb5447848ff6bdd3477aac5ab193363fd666abcf /src/Module.zig
parent4996c2b6a94b042d86b50eb61c9d8d98e63415af (diff)
downloadzig-12087d4cbaab39acadc29716e92765c92b92e28c.tar.gz
zig-12087d4cbaab39acadc29716e92765c92b92e28c.zip
stage2: fix incremental compilation handling of parse errors
Before, incremental compilation would crash when trying to emit compile errors for the update after introducing a parse error. Parse errors are handled by not invalidating any existing semantic analysis. However, only the parse error must be reported, with all the other errors suppressed. Once the parse error is fixed, the new file can be treated as an update to the previously-succeeded update.
Diffstat (limited to 'src/Module.zig')
-rw-r--r--src/Module.zig19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/Module.zig b/src/Module.zig
index 98dad994bd..ccf6996cae 100644
--- a/src/Module.zig
+++ b/src/Module.zig
@@ -65,8 +65,8 @@ emit_h_failed_decls: std.AutoArrayHashMapUnmanaged(*Decl, *ErrorMsg) = .{},
/// Keep track of one `@compileLog` callsite per owner Decl.
compile_log_decls: std.AutoArrayHashMapUnmanaged(*Decl, SrcLoc) = .{},
/// Using a map here for consistency with the other fields here.
-/// The ErrorMsg memory is owned by the `Scope`, using Module's general purpose allocator.
-failed_files: std.AutoArrayHashMapUnmanaged(*Scope, *ErrorMsg) = .{},
+/// The ErrorMsg memory is owned by the `Scope.File`, using Module's general purpose allocator.
+failed_files: std.AutoArrayHashMapUnmanaged(*Scope.File, *ErrorMsg) = .{},
/// Using a map here for consistency with the other fields here.
/// The ErrorMsg memory is owned by the `Export`, using Module's general purpose allocator.
failed_exports: std.AutoArrayHashMapUnmanaged(*Export, *ErrorMsg) = .{},
@@ -732,10 +732,12 @@ pub const Scope = struct {
pub fn unload(file: *File, gpa: *Allocator) void {
switch (file.status) {
- .never_loaded,
.unloaded_parse_failure,
+ .never_loaded,
.unloaded_success,
- => {},
+ => {
+ file.status = .unloaded_success;
+ },
.loaded_success => {
file.tree.deinit(gpa);
@@ -3241,7 +3243,7 @@ pub fn getAstTree(mod: *Module, root_scope: *Scope.File) !*const ast.Tree {
.msg = msg.toOwnedSlice(),
};
- mod.failed_files.putAssumeCapacityNoClobber(&root_scope.base, err_msg);
+ mod.failed_files.putAssumeCapacityNoClobber(root_scope, err_msg);
root_scope.status = .unloaded_parse_failure;
return error.AnalysisFail;
}
@@ -4691,3 +4693,10 @@ pub fn parseStrLit(
},
}
}
+
+pub fn unloadFile(mod: *Module, file_scope: *Scope.File) void {
+ if (file_scope.status == .unloaded_parse_failure) {
+ mod.failed_files.swapRemove(file_scope).?.value.destroy(mod.gpa);
+ }
+ file_scope.unload(mod.gpa);
+}