lib/pluck/src/toplevel/incremental.zig

daab053ee43316e1809a84551d573ddd1e5bf3d2

 1 const pluck = @import("../root.zig");
 2 
 3 const evaluator = pluck.evaluator;
 4 const lpsmc_module = pluck.lpsmc;
 5 const IncrementalLPSMC = evaluator.IncrementalLPSMC;
 6 
 7 const bdd = pluck.bdd;
 8 
 9 const context_owner = @import("context.zig");
10 const ToplevelContext = context_owner.ToplevelContext;
11 
12 pub fn enableIncrementalLPSMC(self: *ToplevelContext) !void {
13     if (self.incremental_lpsmc != null) {
14         return error.AlreadyEnabled;
15     }
16     const lpsmc = try self.allocator.create(IncrementalLPSMC);
17     lpsmc.* = lpsmc_module.init(self.allocator);
18     self.incremental_lpsmc = lpsmc;
19 }
20 
21 pub fn disableIncrementalLPSMC(self: *ToplevelContext) void {
22     if (self.incremental_lpsmc) |lpsmc| {
23         lpsmc_module.deinit(lpsmc);
24         self.allocator.destroy(lpsmc);
25         self.incremental_lpsmc = null;
26     }
27 }
28 
29 pub fn isIncrementalLPSMCEnabled(self: *const ToplevelContext) bool {
30     return self.incremental_lpsmc != null;
31 }
32 
33 pub fn getIncrementalLPSMC(self: *ToplevelContext) ?*IncrementalLPSMC {
34     return self.incremental_lpsmc;
35 }
36 
37 pub fn getLPSMCVarianceStats(self: *const ToplevelContext) ?evaluator.LPSMCVarianceStats {
38     if (self.incremental_lpsmc) |lpsmc| {
39         return lpsmc.variance_stats;
40     }
41     return null;
42 }
43 
44 pub fn getLpsmcRunStats(self: *const ToplevelContext) ?evaluator.LpsmcRunStats {
45     if (self.incremental_lpsmc) |lpsmc| {
46         return lpsmc.last_run_stats;
47     }
48     return null;
49 }
50 
51 pub fn refinementAffectsPathChoices(self: *const ToplevelContext, var_label: bdd.VarLabel) bool {
52     if (self.incremental_lpsmc) |lpsmc| {
53         return lpsmc_module.affectsPathChoices(lpsmc, var_label);
54     }
55     return false;
56 }
57 
58 pub fn invalidateForRefinement(self: *ToplevelContext, var_label: bdd.VarLabel) bool {
59     if (self.incremental_lpsmc) |lpsmc| {
60         return lpsmc_module.invalidateForRefinement(lpsmc, var_label);
61     }
62     return false;
63 }
64 
65 pub fn clearLPSMCCaches(self: *ToplevelContext) void {
66     if (self.incremental_lpsmc) |lpsmc| {
67         lpsmc_module.clearCaches(lpsmc);
68     }
69 }