Skip to content

Commit

Permalink
Output list of non-normalized defs after pre-reduce
Browse files Browse the repository at this point in the history
  • Loading branch information
developedby committed Apr 4, 2024
1 parent 5f782ea commit fe592e0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
9 changes: 6 additions & 3 deletions src/run/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,22 @@ impl<'h, M: Mode> Net<'h, M> {

impl<'a, M: Mode> Net<'a, M> {
/// Reduces at most `limit` redexes.
///
/// If normalized, returns Some(num redexes).
/// If stopped because the limit was reached, returns None.
#[inline(always)]
pub fn reduce(&mut self, limit: usize) -> usize {
pub fn reduce(&mut self, limit: usize) -> Option<usize> {
assert!(!M::LAZY);
let mut count = 0;

while let Some((a, b)) = self.redexes.pop() {
self.interact(a, b);
count += 1;
if count >= limit {
break;
return None;
}
}
count
Some(count)
}

// Lazy mode weak head normalizer
Expand Down
22 changes: 15 additions & 7 deletions src/transform/pre_reduce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Book {
///
/// Defs that are not in the book are treated as inert defs.
///
/// `max_memory` is measured in words.
/// `max_memory` is measured in bytes.
pub fn pre_reduce(
&mut self,
skip: &dyn Fn(&str) -> bool,
Expand Down Expand Up @@ -65,24 +65,32 @@ impl Book {

let State { seen, rewrites, .. } = state;

let mut not_normal = vec![];
for (nam, state) in seen {
if let SeenState::Reduced(net) = state {
self.nets.insert(nam, net);
match state {
SeenState::Reduced { net, normal } => {
if !normal {
not_normal.push(nam.clone());
}
self.nets.insert(nam, net);
}
_ => {}
}
}

PreReduceStats { rewrites, errors: vec![] }
PreReduceStats { rewrites, not_normal, errors: vec![] }
}
}

pub struct PreReduceStats {
pub rewrites: Rewrites,
pub not_normal: Vec<String>,
pub errors: Vec<String>,
}

enum SeenState {
Cycled,
Reduced(Net),
Reduced { net: Net, normal: bool },
}

/// A Def that pushes all interactions to its inner Vec.
Expand Down Expand Up @@ -138,7 +146,7 @@ impl<'a> State<'a> {

let mut rt = run::Net::<run::Strict>::new(self.area);
rt.boot(self.host.defs.get(nam).expect("No function."));
rt.reduce(self.max_rwts as usize);
let n_reduced = rt.reduce(self.max_rwts as usize);

self.rewrites += rt.rwts;

Expand All @@ -155,6 +163,6 @@ impl<'a> State<'a> {
};

// Replace the "Cycled" state with the "Reduced" state
*self.seen.get_mut(nam).unwrap() = SeenState::Reduced(net);
*self.seen.get_mut(nam).unwrap() = SeenState::Reduced { net, normal: n_reduced.is_some() };
}
}

0 comments on commit fe592e0

Please sign in to comment.