authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-03-09 18:08:54-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-03-15 10:48:14-07:00
log3b00e341fd8d1f12a3a14ee79a675a36549e716b
tree23f3ee1522e9e9b980810b3516b90595beee73a8
parent25c3878c00b92ffc884d89d32817ca9c244f7972

AstGen: skip walking the AST when there are parse errors

The AST -> ZIR lowering process assumes an AST that does not have any parse errors.

1 files changed, 19 insertions(+), 15 deletions(-)

src/AstGen.zig+19-15
...@@ -133,8 +133,6 @@ pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir {...@@ -133,8 +133,6 @@ pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir {
133 try astgen.extra.ensureTotalCapacity(gpa, tree.nodes.len + reserved_count);133 try astgen.extra.ensureTotalCapacity(gpa, tree.nodes.len + reserved_count);
134 astgen.extra.items.len += reserved_count;134 astgen.extra.items.len += reserved_count;
135135
136 try lowerAstErrors(&astgen);
137
138 var top_scope: Scope.Top = .{};136 var top_scope: Scope.Top = .{};
139137
140 var gz_instructions: std.ArrayListUnmanaged(Zir.Inst.Index) = .{};138 var gz_instructions: std.ArrayListUnmanaged(Zir.Inst.Index) = .{};
...@@ -150,18 +148,24 @@ pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir {...@@ -150,18 +148,24 @@ pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir {
150 };148 };
151 defer gz_instructions.deinit(gpa);149 defer gz_instructions.deinit(gpa);
152150
153 if (AstGen.structDeclInner(151 // The AST -> ZIR lowering process assumes an AST that does not have any
154 &gen_scope,152 // parse errors.
155 &gen_scope.base,153 if (tree.errors.len == 0) {
156 0,154 if (AstGen.structDeclInner(
157 tree.containerDeclRoot(),155 &gen_scope,
158 .Auto,156 &gen_scope.base,
159 0,157 0,
160 )) |struct_decl_ref| {158 tree.containerDeclRoot(),
161 assert(refToIndex(struct_decl_ref).? == 0);159 .Auto,
162 } else |err| switch (err) {160 0,
163 error.OutOfMemory => return error.OutOfMemory,161 )) |struct_decl_ref| {
164 error.AnalysisFail => {}, // Handled via compile_errors below.162 assert(refToIndex(struct_decl_ref).? == 0);
163 } else |err| switch (err) {
164 error.OutOfMemory => return error.OutOfMemory,
165 error.AnalysisFail => {}, // Handled via compile_errors below.
166 }
167 } else {
168 try lowerAstErrors(&astgen);
165 }169 }
166170
167 const err_index = @enumToInt(Zir.ExtraIndex.compile_errors);171 const err_index = @enumToInt(Zir.ExtraIndex.compile_errors);
...@@ -12642,7 +12646,7 @@ fn emitDbgStmt(gz: *GenZir, line: u32, column: u32) !void {...@@ -12642,7 +12646,7 @@ fn emitDbgStmt(gz: *GenZir, line: u32, column: u32) !void {
1264212646
12643fn lowerAstErrors(astgen: *AstGen) !void {12647fn lowerAstErrors(astgen: *AstGen) !void {
12644 const tree = astgen.tree;12648 const tree = astgen.tree;
12645 if (tree.errors.len == 0) return;12649 assert(tree.errors.len > 0);
1264612650
12647 const gpa = astgen.gpa;12651 const gpa = astgen.gpa;
12648 const parse_err = tree.errors[0];12652 const parse_err = tree.errors[0];