Skip to content

Commit

Permalink
Merge pull request #666 from powdr-labs/symbol_counters
Browse files Browse the repository at this point in the history
Use symbol counters.
  • Loading branch information
chriseth authored Oct 4, 2023
2 parents be12c9c + f4b3468 commit 7081a5a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion ast/src/analyzed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ impl Symbol {
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum SymbolKind {
/// Fixed, witness or intermediate polynomial
Poly(PolynomialType),
Expand Down
23 changes: 12 additions & 11 deletions pil_analyzer/src/pil_analyzer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::{HashMap, HashSet};
use std::collections::{BTreeMap, HashMap, HashSet};
use std::fs;
use std::path::{Path, PathBuf};

Expand Down Expand Up @@ -44,10 +44,7 @@ struct PILAnalyzer<T> {
included_files: HashSet<PathBuf>,
line_starts: Vec<usize>,
current_file: PathBuf,
commit_poly_counter: u64,
constant_poly_counter: u64,
intermediate_poly_counter: u64,
other_symbol_counter: u64,
symbol_counters: BTreeMap<SymbolKind, u64>,
identity_counter: HashMap<IdentityKind, u64>,
local_variables: HashMap<String, u64>,
macro_expander: MacroExpander<T>,
Expand Down Expand Up @@ -101,6 +98,15 @@ impl<T: FieldElement> PILAnalyzer<T> {
pub fn new() -> PILAnalyzer<T> {
PILAnalyzer {
namespace: "Global".to_string(),
symbol_counters: [
SymbolKind::Poly(PolynomialType::Committed),
SymbolKind::Poly(PolynomialType::Constant),
SymbolKind::Poly(PolynomialType::Intermediate),
SymbolKind::Other(),
]
.into_iter()
.map(|k| (k, 0))
.collect(),
..Default::default()
}
}
Expand Down Expand Up @@ -365,12 +371,7 @@ impl<T: FieldElement> PILAnalyzer<T> {
if length.is_some() {
assert!(value.is_none());
}
let counter = match symbol_kind {
SymbolKind::Poly(PolynomialType::Committed) => &mut self.commit_poly_counter,
SymbolKind::Poly(PolynomialType::Constant) => &mut self.constant_poly_counter,
SymbolKind::Poly(PolynomialType::Intermediate) => &mut self.intermediate_poly_counter,
SymbolKind::Other() => &mut self.other_symbol_counter,
};
let counter = self.symbol_counters.get_mut(&symbol_kind).unwrap();
let id = *counter;
*counter += length.unwrap_or(1);
let absolute_name = self.namespaced(&name);
Expand Down

0 comments on commit 7081a5a

Please sign in to comment.