From 3f7d9b5fc19e4081236b3b63aebbc80e1b17f5b5 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 30 Dec 2020 22:31:56 -0700 Subject: stage2: rework Value Payload layout This is the same as the previous commit but for Value instead of Type. Add `Value.castTag` and note that it is preferable to call than `Value.cast`. This matches other abstractions in the codebase. Added a convenience function `Value.Tag.create` which really cleans up the callsites of creating `Value` objects. `Value` tags can now share payload types. This is in preparation for another improvement that I want to do. --- src/Compilation.zig | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/Compilation.zig') diff --git a/src/Compilation.zig b/src/Compilation.zig index 11c8303fac..cd3db84ec2 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -1457,11 +1457,12 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor .complete, .codegen_failure_retryable => { const module = self.bin_file.options.module.?; - if (decl.typed_value.most_recent.typed_value.val.cast(Value.Payload.Function)) |payload| { - switch (payload.func.analysis) { - .queued => module.analyzeFnBody(decl, payload.func) catch |err| switch (err) { + if (decl.typed_value.most_recent.typed_value.val.castTag(.function)) |payload| { + const func = payload.data; + switch (func.analysis) { + .queued => module.analyzeFnBody(decl, func) catch |err| switch (err) { error.AnalysisFail => { - assert(payload.func.analysis != .in_progress); + assert(func.analysis != .in_progress); continue; }, error.OutOfMemory => return error.OutOfMemory, @@ -1475,7 +1476,7 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor 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 {}\n", .{decl.name}); - try liveness.analyze(module.gpa, &decl_arena.allocator, payload.func.analysis.success); + try liveness.analyze(module.gpa, &decl_arena.allocator, func.analysis.success); } assert(decl.typed_value.most_recent.typed_value.ty.hasCodeGenBits()); -- cgit v1.2.3