weir/fixed_point_graph/
plan.rs1use super::{FixedPointAnalysisKind, FixedPointForwardGraph};
2
3#[derive(Clone, Debug, PartialEq)]
5pub struct FixedPointAnalysisPlan {
6 pub(crate) kind: FixedPointAnalysisKind,
7 pub(crate) graph: FixedPointForwardGraph,
8 pub(crate) program: vyre::ir::Program,
9}
10
11impl FixedPointAnalysisPlan {
12 #[must_use]
14 pub fn new(graph: FixedPointForwardGraph, program: vyre::ir::Program) -> Self {
15 Self::new_for_kind(FixedPointAnalysisKind::Generic, graph, program)
16 }
17
18 #[must_use]
20 pub fn new_for_kind(
21 kind: FixedPointAnalysisKind,
22 graph: FixedPointForwardGraph,
23 program: vyre::ir::Program,
24 ) -> Self {
25 Self {
26 kind,
27 graph,
28 program,
29 }
30 }
31
32 #[must_use]
34 pub fn kind(&self) -> FixedPointAnalysisKind {
35 self.kind
36 }
37
38 pub fn require_kind(
40 &self,
41 expected: FixedPointAnalysisKind,
42 consumer: &str,
43 ) -> Result<(), String> {
44 if self.kind == expected {
45 return self.graph.require_kind(expected, consumer);
46 }
47 Err(format!(
48 "{consumer} received a {:?} fixed-point plan, expected {:?}. Fix: prepare the plan with the matching Weir analysis constructor.",
49 self.kind, expected
50 ))
51 }
52
53 #[must_use]
55 pub fn graph(&self) -> &FixedPointForwardGraph {
56 &self.graph
57 }
58
59 #[must_use]
61 pub fn graph_mut(&mut self) -> &mut FixedPointForwardGraph {
62 &mut self.graph
63 }
64
65 #[must_use]
67 pub fn program(&self) -> &vyre::ir::Program {
68 &self.program
69 }
70
71 pub fn replace_program_for_kind(
73 &mut self,
74 kind: FixedPointAnalysisKind,
75 program: vyre::ir::Program,
76 ) {
77 self.kind = kind;
78 self.program = program;
79 }
80
81 #[must_use]
83 pub fn retained_graph_bytes(&self) -> usize {
84 self.graph.retained_bytes()
85 }
86
87 #[must_use]
89 pub fn stable_layout_hash(&self) -> u64 {
90 self.graph.stable_layout_hash()
91 }
92}