Skip to content

Commit

Permalink
Merge pull request ziglang#7647 from ziglang/stage2-comptime-fn-call
Browse files Browse the repository at this point in the history
stage2: comptime function calls and inline function calls
  • Loading branch information
andrewrk authored Jan 3, 2021
2 parents 3d151fb + 6548322 commit d8f3f14
Show file tree
Hide file tree
Showing 17 changed files with 884 additions and 590 deletions.
2 changes: 0 additions & 2 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ pub fn build(b: *Builder) !void {
}

const log_scopes = b.option([]const []const u8, "log", "Which log scopes to enable") orelse &[0][]const u8{};
const zir_dumps = b.option([]const []const u8, "dump-zir", "Which functions to dump ZIR for before codegen") orelse &[0][]const u8{};

const opt_version_string = b.option([]const u8, "version-string", "Override Zig version string. Default is to find out with git.");
const version = if (opt_version_string) |version| version else v: {
Expand Down Expand Up @@ -277,7 +276,6 @@ pub fn build(b: *Builder) !void {
exe.addBuildOption(std.SemanticVersion, "semver", semver);

exe.addBuildOption([]const []const u8, "log_scopes", log_scopes);
exe.addBuildOption([]const []const u8, "zir_dumps", zir_dumps);
exe.addBuildOption(bool, "enable_tracy", tracy != null);
exe.addBuildOption(bool, "is_stage1", is_stage1);
if (tracy) |tracy_path| {
Expand Down
15 changes: 10 additions & 5 deletions src/Compilation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1459,24 +1459,29 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor
const module = self.bin_file.options.module.?;
if (decl.typed_value.most_recent.typed_value.val.castTag(.function)) |payload| {
const func = payload.data;
switch (func.analysis) {
switch (func.state) {
.queued => module.analyzeFnBody(decl, func) catch |err| switch (err) {
error.AnalysisFail => {
assert(func.analysis != .in_progress);
assert(func.state != .in_progress);
continue;
},
error.OutOfMemory => return error.OutOfMemory,
},
.in_progress => unreachable,
.inline_only => unreachable, // don't queue work for this
.sema_failure, .dependency_failure => continue,
.success => {},
}
// Here we tack on additional allocations to the Decl's arena. The allocations are
// lifetime annotations in the ZIR.
// Here we tack on additional allocations to the Decl's arena. The allocations
// are lifetime annotations in the ZIR.
var decl_arena = decl.typed_value.most_recent.arena.?.promote(module.gpa);
defer decl.typed_value.most_recent.arena.?.* = decl_arena.state;
log.debug("analyze liveness of {s}\n", .{decl.name});
try liveness.analyze(module.gpa, &decl_arena.allocator, func.analysis.success);
try liveness.analyze(module.gpa, &decl_arena.allocator, func.body);

if (std.builtin.mode == .Debug and self.verbose_ir) {
func.dump(module.*);
}
}

assert(decl.typed_value.most_recent.typed_value.ty.hasCodeGenBits());
Expand Down
Loading

0 comments on commit d8f3f14

Please sign in to comment.