#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum BranchStrategy {
LocalRepair,
AlternativeApproach,
DiagnosticProbe,
DistinctFamily,
}
impl BranchStrategy {
pub(crate) fn id(&self) -> &'static str {
match self {
BranchStrategy::LocalRepair => "local-repair",
BranchStrategy::AlternativeApproach => "alternative-approach",
BranchStrategy::DiagnosticProbe => "diagnostic-probe",
BranchStrategy::DistinctFamily => "distinct-family",
}
}
pub(crate) fn continues_partial(&self) -> bool {
matches!(
self,
BranchStrategy::LocalRepair | BranchStrategy::DiagnosticProbe
)
}
pub(crate) fn goal_fragment(&self) -> &'static str {
match self {
BranchStrategy::LocalRepair => {
"Continue the current approach: make the smallest change that \
clears the remaining diagnostics listed below."
}
BranchStrategy::AlternativeApproach => {
"Earlier attempts failed with the same signature. Discard that \
approach entirely and implement a genuinely different \
algorithm or structure for the goal."
}
BranchStrategy::DiagnosticProbe => {
"Before editing further, run the verifier tools (run_test, \
run_build) and read the failing output to localize the fault; \
then fix exactly what the evidence names."
}
BranchStrategy::DistinctFamily => {
"Approach the goal independently from first principles; do not \
assume any earlier partial attempt exists."
}
}
}
}
#[derive(Debug, Clone, Copy, Default)]
pub(crate) struct BranchSummary {
pub repeated_signature: bool,
pub obligations_decreased: bool,
pub energy_improved: bool,
}
pub(crate) fn next_strategy(previous: BranchSummary) -> BranchStrategy {
if previous.repeated_signature {
BranchStrategy::AlternativeApproach
} else if previous.obligations_decreased {
BranchStrategy::LocalRepair
} else if !previous.energy_improved {
BranchStrategy::DistinctFamily
} else {
BranchStrategy::DiagnosticProbe
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn triggers_select_distinct_behaviors() {
assert_eq!(
next_strategy(BranchSummary {
repeated_signature: true,
..Default::default()
}),
BranchStrategy::AlternativeApproach
);
assert_eq!(
next_strategy(BranchSummary {
obligations_decreased: true,
..Default::default()
}),
BranchStrategy::LocalRepair
);
assert_eq!(
next_strategy(BranchSummary::default()),
BranchStrategy::DistinctFamily
);
assert_eq!(
next_strategy(BranchSummary {
energy_improved: true,
..Default::default()
}),
BranchStrategy::DiagnosticProbe
);
assert!(BranchStrategy::LocalRepair.continues_partial());
assert!(!BranchStrategy::AlternativeApproach.continues_partial());
}
}