Skip to content

Commit

Permalink
Rename and minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gzanitti committed Aug 15, 2024
1 parent 1d4cf5c commit 63b65c0
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion ast/src/analyzed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub enum StatementIdentifier {
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)]
pub struct Analyzed<T> {
pub definitions: HashMap<String, (Symbol, Option<FunctionValueDefinition>)>,
pub trait_impls: HashMap<String, Vec<TraitImplementation<Expression>>>,
pub public_declarations: HashMap<String, PublicDeclaration>,
pub intermediate_columns: HashMap<String, (Symbol, Vec<AlgebraicExpression<T>>)>,
pub identities: Vec<Identity<SelectedExpressions<AlgebraicExpression<T>>>>,
Expand All @@ -44,7 +45,6 @@ pub struct Analyzed<T> {
pub source_order: Vec<StatementIdentifier>,
/// Symbols from the core that were added automatically but will not be printed.
pub auto_added_symbols: HashSet<String>,
pub implementations: HashMap<String, Vec<TraitImplementation<Expression>>>,
}

impl<T> Analyzed<T> {
Expand Down
6 changes: 3 additions & 3 deletions executor/src/constant_evaluator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn generate_values<T: FieldElement>(
) -> Vec<T> {
let symbols = CachedSymbols {
symbols: &analyzed.definitions,
implementations: &analyzed.implementations,
trait_impls: &analyzed.trait_impls,
cache: Arc::new(RwLock::new(Default::default())),
degree,
};
Expand Down Expand Up @@ -172,7 +172,7 @@ type SymbolCache<'a, T> = HashMap<String, BTreeMap<Option<Vec<Type>>, Arc<Value<
#[derive(Clone)]
pub struct CachedSymbols<'a, T> {
symbols: &'a HashMap<String, (Symbol, Option<FunctionValueDefinition>)>,
implementations: &'a HashMap<String, Vec<TraitImplementation<Expression>>>,
trait_impls: &'a HashMap<String, Vec<TraitImplementation<Expression>>>,
cache: Arc<RwLock<SymbolCache<'a, T>>>,
degree: DegreeType,
}
Expand Down Expand Up @@ -211,7 +211,7 @@ impl<'a, T: FieldElement> SymbolLookup<'a, T> for CachedSymbols<'a, T> {
&self,
trait_name: &str,
) -> Result<&'a Vec<TraitImplementation<Expression>>, EvalError> {
match self.implementations.get(trait_name) {
match self.trait_impls.get(trait_name) {
Some(impls) => Ok(impls),
None => Err(EvalError::SymbolNotFound(format!(
"Trait {trait_name} not found."
Expand Down
2 changes: 1 addition & 1 deletion executor/src/witgen/query_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl<'a, T: FieldElement> SymbolLookup<'a, T> for Symbols<'a, T> {
&self,
trait_name: &str,
) -> Result<&'a Vec<powdr_ast::parsed::TraitImplementation<Expression>>, EvalError> {
match self.fixed_data.analyzed.implementations.get(trait_name) {
match self.fixed_data.analyzed.trait_impls.get(trait_name) {
Some(implementations) => Ok(implementations),
None => Err(EvalError::SymbolNotFound(format!(
"Trait {trait_name} not found."
Expand Down
17 changes: 9 additions & 8 deletions pil-analyzer/src/condenser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ type AnalyzedIdentity<T> = Identity<SelectedExpressions<AlgebraicExpression<T>>>

pub fn condense<T: FieldElement>(
mut definitions: HashMap<String, (Symbol, Option<FunctionValueDefinition>)>,
implementations: HashMap<String, Vec<TraitImplementation<Expression>>>,
trait_impls: HashMap<String, Vec<TraitImplementation<Expression>>>,
mut public_declarations: HashMap<String, PublicDeclaration>,
identities: &[ParsedIdentity],
source_order: Vec<StatementIdentifier>,
auto_added_symbols: HashSet<String>,
) -> Analyzed<T> {
let mut condenser = Condenser::new(&definitions, &implementations);
let mut condenser = Condenser::new(&definitions, &trait_impls);

let mut condensed_identities = vec![];
let mut intermediate_columns = HashMap::new();
Expand Down Expand Up @@ -175,7 +175,7 @@ pub fn condense<T: FieldElement>(
}
Analyzed {
definitions,
implementations,
trait_impls,
public_declarations,
intermediate_columns,
identities: condensed_identities,
Expand All @@ -190,6 +190,8 @@ pub struct Condenser<'a, T> {
degree: Option<DegreeType>,
/// All the definitions from the PIL file.
symbols: &'a HashMap<String, (Symbol, Option<FunctionValueDefinition>)>,
/// All the trait implementations from the PIL file.
trait_impls: &'a HashMap<String, Vec<TraitImplementation<Expression>>>,
/// Evaluation cache.
symbol_values: SymbolCache<'a, T>,
/// Current namespace (for names of generated columns).
Expand All @@ -205,13 +207,12 @@ pub struct Condenser<'a, T> {
/// The names of all new columns ever generated, to avoid duplicates.
new_symbols: HashSet<String>,
new_constraints: Vec<AnalyzedIdentity<T>>,
implementations: &'a HashMap<String, Vec<TraitImplementation<Expression>>>,
}

impl<'a, T: FieldElement> Condenser<'a, T> {
pub fn new(
symbols: &'a HashMap<String, (Symbol, Option<FunctionValueDefinition>)>,
implementations: &'a HashMap<String, Vec<TraitImplementation<Expression>>>,
trait_impls: &'a HashMap<String, Vec<TraitImplementation<Expression>>>,
) -> Self {
let counters = Counters::with_existing(symbols.values().map(|(sym, _)| sym), None, None);
Self {
Expand All @@ -225,7 +226,7 @@ impl<'a, T: FieldElement> Condenser<'a, T> {
new_intermediate_column_values: Default::default(),
new_symbols: HashSet::new(),
new_constraints: vec![],
implementations,
trait_impls,
}
}

Expand Down Expand Up @@ -363,7 +364,7 @@ impl<'a, T: FieldElement> SymbolLookup<'a, T> for Condenser<'a, T> {
}

fn lookup_public_reference(&self, name: &str) -> Result<Arc<Value<'a, T>>, EvalError> {
Definitions(self.symbols, self.implementations).lookup_public_reference(name)
Definitions(self.symbols, self.trait_impls).lookup_public_reference(name)
}

fn degree(&self) -> Result<Arc<Value<'a, T>>, EvalError> {
Expand Down Expand Up @@ -559,7 +560,7 @@ impl<'a, T: FieldElement> SymbolLookup<'a, T> for Condenser<'a, T> {
&self,
trait_name: &str,
) -> Result<&'a Vec<TraitImplementation<Expression>>, EvalError> {
match self.implementations.get(trait_name) {
match self.trait_impls.get(trait_name) {
Some(impls) => Ok(impls),
None => Err(EvalError::SymbolNotFound(format!(
"Trait {trait_name} not found."
Expand Down
10 changes: 5 additions & 5 deletions pil-analyzer/src/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -880,9 +880,9 @@ impl<'a, 'b, T: FieldElement, S: SymbolLookup<'a, T>> Evaluator<'a, 'b, T, S> {
};
Value::Closure(closure).into()
}
None => Err(EvalError::SymbolNotFound(format!(
"Function {fn_name} not found in trait {trait_name}"
)))?,
None => {
panic!("Function {fn_name} not found in trait {trait_name}")
}
}
}
None => self.symbols.lookup(&poly.name, &type_args)?,
Expand Down Expand Up @@ -1349,15 +1349,15 @@ mod test {
};
evaluate::<GoldilocksField>(
symbol,
&mut Definitions(&analyzed.definitions, &analyzed.implementations),
&mut Definitions(&analyzed.definitions, &analyzed.trait_impls),
)
.unwrap()
.to_string()
}

pub fn evaluate_function<T: FieldElement>(input: &str, function: &str) -> T {
let analyzed = analyze_string::<GoldilocksField>(input);
let mut symbols = evaluator::Definitions(&analyzed.definitions, &analyzed.implementations);
let mut symbols = evaluator::Definitions(&analyzed.definitions, &analyzed.trait_impls);
let function = symbols.lookup(function, &None).unwrap();
let result = evaluator::evaluate_function_call(function, vec![], &mut symbols)
.unwrap()
Expand Down
8 changes: 4 additions & 4 deletions pil-analyzer/src/traits_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ use powdr_ast::{
};

pub struct TraitsProcessor<'a> {
implementations: &'a HashMap<String, Vec<TraitImplementation<Expression>>>,
trait_impls: &'a HashMap<String, Vec<TraitImplementation<Expression>>>,
}

impl<'a> TraitsProcessor<'a> {
pub fn new(implementations: &'a HashMap<String, Vec<TraitImplementation<Expression>>>) -> Self {
Self { implementations }
pub fn new(trait_impls: &'a HashMap<String, Vec<TraitImplementation<Expression>>>) -> Self {
Self { trait_impls }
}

pub fn traits_resolution(
Expand Down Expand Up @@ -52,7 +52,7 @@ impl<'a> TraitsProcessor<'a> {
return None;
};

if let Some(impls) = self.implementations.get(&trait_decl.name) {
if let Some(impls) = self.trait_impls.get(&trait_decl.name) {
for (index, impl_) in impls.iter().enumerate() {
let Some(_) = impl_.function_by_name(&trait_fn.name) else {
panic!(
Expand Down
2 changes: 1 addition & 1 deletion pipeline/src/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ pub fn evaluate_function<'a, T: FieldElement>(
function: &'a str,
arguments: Vec<Arc<evaluator::Value<'a, T>>>,
) -> evaluator::Value<'a, T> {
let mut symbols = evaluator::Definitions(&analyzed.definitions, &analyzed.implementations);
let mut symbols = evaluator::Definitions(&analyzed.definitions, &analyzed.trait_impls);
let function = symbols.lookup(function, &None).unwrap();
evaluator::evaluate_function_call(function, arguments, &mut symbols)
.unwrap()
Expand Down

0 comments on commit 63b65c0

Please sign in to comment.