tiny.choir.Pass
Defined in tiny.choir.
API (23)
Actions
Public operations.
cloneForParallelTargetdeinitisolatedMutationparallelStateSafereadOnlyrunsameRerunIdentityvalidRerunContractwholeModuleMutation
Fields and members
Public fields and members.
dependent_dialectsdescriptionmutation_scopenameowns_textual_optionsrerun_policyrun_fnrun_with_state_fnstatestate_clone_fnstate_concurrencystate_deinit_fntextual_optionswork_contract
Source
Source: lib/choir/src/passes/pass/base.zig:11
zig
pub const Pass = struct { work_contract: ?subject.work.Contract = null, name: []const u8, description: []const u8, run_fn: ?*const fn (*PassContext) PassResult = null, state: ?*anyopaque = null, run_with_state_fn: ?*const fn (?*anyopaque, *PassContext) PassResult = null, state_concurrency: PassStateConcurrency = .exclusive, rerun_policy: PassRerunPolicy = .always, state_clone_fn: ?*const fn (?*anyopaque, std.mem.Allocator) anyerror!?*anyopaque = null, state_deinit_fn: ?*const fn (?*anyopaque, std.mem.Allocator) void = null, mutation_scope: PassMutationScope = .whole_module, dependent_dialects: DependentDialects = &.{}, textual_options: ?[]const u8 = null, owns_textual_options: bool = false, pub fn run(self: Pass, ctx: *PassContext) PassResult { if (self.run_with_state_fn) |run_with_state| { return run_with_state(self.state, ctx); } if (self.run_fn) |run_pass| { return run_pass(ctx); } return .failure; } pub fn readOnly(self: Pass) bool { return self.mutation_scope == .read_only; } pub fn isolatedMutation(self: Pass) bool { return self.mutation_scope == .isolated; } pub fn wholeModuleMutation(self: Pass) bool { return self.mutation_scope == .whole_module; } pub fn parallelStateSafe(self: Pass) bool { if (self.state == null) return true; if (self.state_concurrency == .shared) return true; return self.state_clone_fn != null; } pub fn validRerunContract(self: Pass) bool { return switch (self.rerun_policy) { .always => true, .skip_if_unchanged => self.state == null and self.run_with_state_fn == null and self.run_fn != null, }; } pub fn sameRerunIdentity(self: Pass, previous: Pass) bool { if (self.rerun_policy != .skip_if_unchanged) return false; if (previous.rerun_policy != .skip_if_unchanged) return false; if (!self.validRerunContract() or !previous.validRerunContract()) return false; if (self.run_fn != previous.run_fn) return false; return std.mem.eql( u8, self.textual_options orelse "", previous.textual_options orelse "", ); } pub fn cloneForParallelTarget(self: Pass, allocator: std.mem.Allocator) anyerror!Pass { var cloned = self; cloned.owns_textual_options = false; if (self.state) |_| { if (self.state_clone_fn) |clone_fn| { cloned.state = try clone_fn(self.state, allocator); return cloned; } if (self.state_concurrency == .shared) { cloned.state_deinit_fn = null; return cloned; } return error.PassStateNotParallel; } cloned.state_deinit_fn = null; return cloned; } pub fn deinit(self: *Pass, allocator: std.mem.Allocator) void { if (self.state_deinit_fn) |deinit_fn| deinit_fn(self.state, allocator); if (self.owns_textual_options) { if (self.textual_options) |text| allocator.free(text); } self.* = undefined; }};Source: lib/choir/src/root.zig:56
zig
pub const Pass = passes.Pass;Also reachable as
passes.Pass, passes.pass.Pass.
Audit
| Definitions | 10 |
|---|---|
| Public names | 30 |
| Members | 14 |
| Version | 26.7.0 |
| Revision | daab053ee433 |