Skip to content

Commit

Permalink
Improve error messagse.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseth committed Feb 5, 2024
1 parent c9b72e2 commit f6024b8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 2 additions & 0 deletions ast/src/analyzed/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub enum Type {
}

impl Type {
/// Returns the column type `int -> fe`.
pub fn col() -> Self {
Type::Function(FunctionType::col())
}
Expand Down Expand Up @@ -117,6 +118,7 @@ pub struct FunctionType {
}

impl FunctionType {
/// Returns the column type `int -> fe`.
pub fn col() -> Self {
FunctionType {
params: vec![Type::Int],
Expand Down
7 changes: 5 additions & 2 deletions executor/src/constant_evaluator/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use std::{collections::HashMap, fmt::Display, rc::Rc};

use itertools::Itertools;
use powdr_ast::analyzed::{types::TypedExpression, Analyzed, FunctionValueDefinition};
use powdr_ast::analyzed::{
types::{Type, TypedExpression},
Analyzed, FunctionValueDefinition,
};
use powdr_number::{DegreeType, FieldElement};
use powdr_pil_analyzer::evaluator::{self, Custom, EvalError, SymbolLookup, Value};
use rayon::prelude::{IntoParallelIterator, ParallelIterator};
Expand Down Expand Up @@ -45,7 +48,7 @@ fn generate_values<T: FieldElement>(
let result = match body {
FunctionValueDefinition::Expression(TypedExpression { e, ty }) => {
if let Some(ty) = ty {
assert_eq!(ty.to_string(), "col")
assert_eq!(ty, &Type::col())
};
(0..degree)
.into_par_iter()
Expand Down
14 changes: 10 additions & 4 deletions pil-analyzer/src/statement_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ where
let length = self
.evaluate_expression(len)
.map_err(|e| {
panic!("Error evaluating array length of witness column {name}:\n{e}")
panic!("Error evaluating length of array of witness columns {name}:\n{e}")
})
.map(|length| length.to_degree())
.ok();
Expand Down Expand Up @@ -207,11 +207,17 @@ where
let ty = ty
.map(|t| {
if let Type::Array(ArrayType { base, length }) = &t {
assert!(length.is_some());
assert_eq!(base.as_ref(), &Type::col());
if base.as_ref() != &Type::col() {
panic!("This declaration has no value and thus must be a witness column array, but its type is {t} instead of col[]");
}
if length.is_none() {
panic!("Explicit array length required for column {name}: {t}");
}
t
} else {
assert_eq!(t, Type::col());
if t != Type::col() {
panic!("This declaration has no value and thus must be a witness column, but its type is {t} instead of col");
}
t
}
})
Expand Down

0 comments on commit f6024b8

Please sign in to comment.