Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
MasonRemaley committed Oct 27, 2023
1 parent a182ccf commit b90831f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 59 deletions.
53 changes: 14 additions & 39 deletions src/AstGen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ const trace = @import("tracy.zig").trace;
const BuiltinFn = @import("BuiltinFn.zig");
const AstRlAnnotate = @import("AstRlAnnotate.zig");

// XXX: temp
pub const astgen_zon = false;

gpa: Allocator,
tree: *const Ast,
/// The set of nodes which, given the choice, must expose a result pointer to
Expand Down Expand Up @@ -117,16 +114,13 @@ fn appendRefsAssumeCapacity(astgen: *AstGen, refs: []const Zir.Inst.Ref) void {
}

pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir {
assert(astgen_zon or tree.mode == .zig);
assert(tree.mode == .zig);

var arena = std.heap.ArenaAllocator.init(gpa);
defer arena.deinit();

// XXX: check no longer needed, see above assertion
var nodes_need_rl: AstRlAnnotate.RlNeededSet = switch (tree.mode) {
.zig => try AstRlAnnotate.annotate(gpa, arena.allocator(), tree),
.zon => .{},
};
var nodes_need_rl = try AstRlAnnotate.annotate(gpa, arena.allocator(), tree);
defer nodes_need_rl.deinit(gpa);

var astgen: AstGen = .{
Expand Down Expand Up @@ -167,37 +161,18 @@ pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir {
// The AST -> ZIR lowering process assumes an AST that does not have any
// parse errors.
if (tree.errors.len == 0) {
switch (tree.mode) {
.zig => if (AstGen.structDeclInner(
&gen_scope,
&gen_scope.base,
0,
tree.containerDeclRoot(),
.Auto,
0,
)) |struct_decl_ref| {
assert(refToIndex(struct_decl_ref).? == 0);
} else |err| switch (err) {
error.OutOfMemory => return error.OutOfMemory,
error.AnalysisFail => {}, // Handled via compile_errors below.
},
.zon => {
const root_node = tree.nodes.items(.data)[0].lhs;
const block_inst = try gen_scope.makeBlockInst(.block, root_node);
assert(block_inst == 0);
if (AstGen.expr(
&gen_scope,
&gen_scope.base,
.{ .rl = .none, .ctx = .none },
root_node,
)) |result_inst| {
_ = try gen_scope.addBreak(.@"break", block_inst, result_inst);
try gen_scope.setBlockBody(block_inst);
} else |err| switch (err) {
error.OutOfMemory => return error.OutOfMemory,
error.AnalysisFail => {}, // Handled via compile_errors below.
}
},
if (AstGen.structDeclInner(
&gen_scope,
&gen_scope.base,
0,
tree.containerDeclRoot(),
.Auto,
0,
)) |struct_decl_ref| {
assert(refToIndex(struct_decl_ref).? == 0);
} else |err| switch (err) {
error.OutOfMemory => return error.OutOfMemory,
error.AnalysisFail => {}, // Handled via compile_errors below.
}
} else {
try lowerAstErrors(&astgen);
Expand Down
37 changes: 17 additions & 20 deletions src/Compilation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2211,7 +2211,7 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void
// that are implemented in stage2 but not stage1.
try comp.astgen_work_queue.ensureUnusedCapacity(module.import_table.count());
for (module.import_table.values()) |value| {
if (@import("AstGen.zig").astgen_zon or Module.mode(value.sub_file_path) != .zon) {
if (Module.mode(value.sub_file_path) == .zig) {
comp.astgen_work_queue.writeItemAssumeCapacity(value);
}
}
Expand Down Expand Up @@ -3519,7 +3519,6 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: *std.Progress.Node) !v
defer named_frame.end();

const module = comp.bin_file.options.module.?;
// XXX: this is failing
module.ensureFuncBodyAnalyzed(func) catch |err| switch (err) {
error.OutOfMemory => return error.OutOfMemory,
error.AnalysisFail => return,
Expand Down Expand Up @@ -3813,7 +3812,7 @@ fn workerAstGenFile(
wg: *WaitGroup,
src: AstGenSrc,
) void {
assert(@import("AstGen.zig").astgen_zon or Module.mode(file.sub_file_path) == .zig);
assert(Module.mode(file.sub_file_path) == .zig);

defer wg.finish();

Expand Down Expand Up @@ -3867,23 +3866,21 @@ fn workerAstGenFile(
}
break :blk res;
};
if (import_result.is_new) {
if (@import("AstGen.zig").astgen_zon or Module.mode(import_result.file.sub_file_path) == .zig) {
log.debug("AstGen of {s} has import '{s}'; queuing AstGen of {s}", .{
file.sub_file_path, import_path, import_result.file.sub_file_path,
});
const sub_src: AstGenSrc = .{ .import = .{
.importing_file = file,
.import_tok = item.data.token,
} };
wg.start();
comp.thread_pool.spawn(workerAstGenFile, .{
comp, import_result.file, prog_node, wg, sub_src,
}) catch {
wg.finish();
continue;
};
}
if (import_result.is_new and Module.mode(import_result.file.sub_file_path) == .zig) {
log.debug("AstGen of {s} has import '{s}'; queuing AstGen of {s}", .{
file.sub_file_path, import_path, import_result.file.sub_file_path,
});
const sub_src: AstGenSrc = .{ .import = .{
.importing_file = file,
.import_tok = item.data.token,
} };
wg.start();
comp.thread_pool.spawn(workerAstGenFile, .{
comp, import_result.file, prog_node, wg, sub_src,
}) catch {
wg.finish();
continue;
};
}
}
}
Expand Down

0 comments on commit b90831f

Please sign in to comment.