kotoba_core/ir/
strategy.rs1use serde::{Deserialize, Serialize};
4use crate::types::*;
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
8#[serde(tag = "op")]
9pub enum StrategyOp {
10 Once {
12 rule: String, },
14
15 Exhaust {
17 rule: String,
18 #[serde(default)]
19 order: Order,
20 #[serde(skip_serializing_if = "Option::is_none")]
21 measure: Option<String>,
22 },
23
24 While {
26 rule: String,
27 pred: String, #[serde(default)]
29 order: Order,
30 },
31
32 Seq {
34 strategies: Vec<Box<StrategyOp>>,
35 },
36
37 Choice {
39 strategies: Vec<Box<StrategyOp>>,
40 },
41
42 Priority {
44 strategies: Vec<PrioritizedStrategy>,
45 },
46}
47
48#[derive(Debug, Clone, Serialize, Deserialize)]
50pub struct PrioritizedStrategy {
51 pub strategy: Box<StrategyOp>,
52 pub priority: i32,
53}
54
55#[derive(Debug, Clone, Serialize, Deserialize, Default)]
57pub enum Order {
58 #[default]
59 #[serde(rename = "topdown")]
60 TopDown,
61
62 #[serde(rename = "bottomup")]
63 BottomUp,
64
65 #[serde(rename = "fair")]
66 Fair,
67}
68
69#[derive(Debug, Clone, Serialize, Deserialize)]
71pub struct StrategyIR {
72 pub strategy: StrategyOp,
73}
74
75#[derive(Debug, Clone)]
77pub struct StrategyResult {
78 pub applied_count: usize,
79 pub final_graph: GraphRef_,
80 pub patches: Vec<crate::ir::patch::Patch>,
81}
82
83pub trait Externs {
85 fn deg_ge(&self, v: VertexId, k: u32) -> bool;
87
88 fn edge_count_nonincreasing(&self, g0: &GraphRef_, g1: &GraphRef_) -> bool;
90
91 fn custom_pred(&self, name: &str, args: &[Value]) -> bool;
93}