Skip to content

Commit

Permalink
use never type for uninstantiated heuristics
Browse files Browse the repository at this point in the history
  • Loading branch information
RagnarGrootKoerkamp committed Mar 28, 2024
1 parent 3de2f13 commit 85e0146
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
8 changes: 8 additions & 0 deletions pa-heuristic/src/heuristic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,11 @@ pub trait HeuristicInstance<'a> {
"".into()
}
}

impl<'a> HeuristicInstance<'a> for ! {
type Hint = ();
type Order = ();
fn h(&self, _pos: Pos) -> Cost {
unreachable!()
}
}
3 changes: 2 additions & 1 deletion pa-heuristic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
associated_type_defaults,
int_roundings,
let_chains,
portable_simd
portable_simd,
never_type
)]

mod cli;
Expand Down
2 changes: 1 addition & 1 deletion pa-vis/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(let_chains, int_roundings)]
#![feature(let_chains, int_roundings, never_type)]

pub mod cli;
#[cfg(feature = "sdl")]
Expand Down
22 changes: 11 additions & 11 deletions pa-vis/src/visualizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use super::{canvas::*, *};
use clap::ValueEnum;
use itertools::Itertools;
use pa_affine_types::*;
use pa_heuristic::matches::{Match, MatchStatus};
use pa_heuristic::matches::MatchStatus;
use pa_types::*;
use rand::rngs::StdRng;
use rand::{Rng, SeedableRng};
Expand Down Expand Up @@ -166,7 +166,7 @@ impl VisualizerInstance for Visualizer {
fn expand_preprune(&mut self, pos: Pos) {
if self.config.style.preprune.is_some() {
self.preprune.push(pos);
self.draw::<NoCostI>(false, None, false, None, None);
self.draw::<!>(false, None, false, None, None);
}
}
fn extend_preprune(&mut self, pos: Pos) {
Expand All @@ -178,7 +178,7 @@ impl VisualizerInstance for Visualizer {
fn expand_trace(&mut self, pos: Pos) {
if self.config.style.trace.is_some() {
self.trace.push(ExpandPos::Single(pos));
self.draw::<NoCostI>(false, None, false, None, None);
self.draw::<!>(false, None, false, None, None);
}
}
fn extend_trace(&mut self, pos: Pos) {
Expand All @@ -190,13 +190,13 @@ impl VisualizerInstance for Visualizer {
fn h_call(&mut self, pos: Pos) {
if pos <= self.target && self.config.style.draw_h_calls {
self.h_calls.push(pos);
self.draw::<NoCostI>(false, None, false, None, None);
self.draw::<!>(false, None, false, None, None);
}
}
fn f_call(&mut self, pos: Pos, in_bounds: bool, fixed: bool) {
if self.config.style.draw_f_calls {
self.f_calls.push((pos, in_bounds, fixed));
self.draw::<NoCostI>(false, None, false, None, None);
self.draw::<!>(false, None, false, None, None);
}
}
fn j_range(&mut self, start: Pos, end: Pos) {
Expand All @@ -206,7 +206,7 @@ impl VisualizerInstance for Visualizer {
} else {
self.j_ranges.push((start, end));
}
self.draw::<NoCostI>(false, None, false, None, None);
self.draw::<!>(false, None, false, None, None);
}
}
fn fixed_j_range(&mut self, start: Pos, end: Pos) {
Expand All @@ -216,14 +216,14 @@ impl VisualizerInstance for Visualizer {
} else {
self.fixed_j_ranges.push((start, end));
}
self.draw::<NoCostI>(false, None, false, None, None);
self.draw::<!>(false, None, false, None, None);
}
}
fn fixed_h(&mut self, start: Pos, end: Pos) {
if self.config.style.draw_ranges {
self.next_fixed_h = None;
self.fixed_h.push((start, end));
self.draw::<NoCostI>(false, None, false, None, None);
self.draw::<!>(false, None, false, None, None);
if let Some(r) = self
.fixed_h
.iter_mut()
Expand All @@ -232,15 +232,15 @@ impl VisualizerInstance for Visualizer {
.find(|(s, _)| s.0 == start.0)
{
*r = (start, end);
self.draw::<NoCostI>(false, None, false, None, None);
self.draw::<!>(false, None, false, None, None);
self.fixed_h.pop();
}
}
}
fn next_fixed_h(&mut self, start: Pos, end: Pos) {
if self.config.style.draw_ranges {
self.next_fixed_h = Some((start, end));
self.draw::<NoCostI>(false, None, false, None, None);
self.draw::<!>(false, None, false, None, None);
}
}

Expand Down Expand Up @@ -291,7 +291,7 @@ impl VisualizerInstance for Visualizer {
let size = Pos(min(size.0, maxsize.0), min(size.1, maxsize.1));
self.trace.push(ExpandPos::Block(pos, size));
if self.config.style.trace.is_some() {
self.draw::<NoCostI>(false, None, false, None, None);
self.draw::<!>(false, None, false, None, None);
}
}

Expand Down

0 comments on commit 85e0146

Please sign in to comment.