Skip to content

Commit

Permalink
refactor: renaming for clarity
Browse files Browse the repository at this point in the history
- rename BindingAccess to SymbolAccess
- rename SymbolType to SymbolBinding
- simplify the SymbolBinding enum variant names
  • Loading branch information
grjte committed Apr 17, 2023
1 parent 48373cf commit e06adfb
Show file tree
Hide file tree
Showing 31 changed files with 392 additions and 392 deletions.
8 changes: 4 additions & 4 deletions air-script-core/src/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ impl Display for AccessType {
}
}

/// [BindingAccess] is used to indicate referencing all or part of an identifier that is bound to a
/// [SymbolAccess] is used to indicate referencing all or part of an identifier that is bound to a
/// value, such as a [ConstantBinding] or a [VariableBinding].
///
/// - `name`: is the identifier of the [ConstantBinding] or [VariableBinding] being accessed.
/// - `access_type`: specifies the [AccessType] by which the identifier is being accessed.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct BindingAccess {
pub struct SymbolAccess {
name: Identifier,
access_type: AccessType,
}

impl BindingAccess {
impl SymbolAccess {
pub fn new(name: Identifier, access_type: AccessType) -> Self {
Self { name, access_type }
}
Expand All @@ -52,7 +52,7 @@ impl BindingAccess {
self.name.name()
}

/// Gets the access type of this [BindingAccess].
/// Gets the access type of this [SymbolAccess].
pub fn access_type(&self) -> &AccessType {
&self.access_type
}
Expand Down
4 changes: 2 additions & 2 deletions air-script-core/src/expression.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use super::{BindingAccess, Identifier, ListFolding, TraceAccess, TraceBindingAccess};
use super::{Identifier, ListFolding, SymbolAccess, TraceAccess, TraceBindingAccess};

/// Arithmetic expressions for evaluation of constraints.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum Expression {
Const(u64),
/// Represents a reference to all or part of a constant, variable, or trace binding.
BindingAccess(BindingAccess),
SymbolAccess(SymbolAccess),
TraceAccess(TraceAccess),
TraceBindingAccess(TraceBindingAccess),
/// Represents a random value provided by the verifier. The first inner value is the name of
Expand Down
2 changes: 1 addition & 1 deletion air-script-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod access;
pub use access::{AccessType, BindingAccess, Iterable, Range};
pub use access::{AccessType, Iterable, Range, SymbolAccess};

mod constant;
pub use constant::{ConstantBinding, ConstantValueExpr};
Expand Down
6 changes: 3 additions & 3 deletions codegen/winterfell/src/air/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ impl Codegen for Value {
ElemType::Base => format!("Felt::new({value})"),
ElemType::Ext => format!("E::from({value}_u64)"),
},
Value::BoundConstant(binding_access) => {
let name = binding_access.name().to_string();
let access_type = binding_access.access_type();
Value::BoundConstant(symbol_access) => {
let name = symbol_access.name().to_string();
let access_type = symbol_access.access_type();
let base_value = match access_type {
AccessType::Default => name,
AccessType::Vector(idx) => format!("{name}[{idx}]"),
Expand Down
22 changes: 11 additions & 11 deletions ir/src/constraint_builder/expression.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{
get_variable_expr, AccessType, BindingAccess, ConstraintBuilder, Expression, ListFolding,
NodeIndex, Operation, SemanticError, SymbolType, TraceAccess, TraceBindingAccess, Value,
get_variable_expr, AccessType, ConstraintBuilder, Expression, ListFolding, NodeIndex,
Operation, SemanticError, SymbolAccess, SymbolBinding, TraceAccess, TraceBindingAccess, Value,
};

impl ConstraintBuilder {
Expand All @@ -27,11 +27,11 @@ impl ConstraintBuilder {
}

// --- IDENTIFIER EXPRESSIONS ---------------------------------------------------------
Expression::BindingAccess(access) => self.insert_symbol_access(access),
Expression::SymbolAccess(access) => self.insert_symbol_access(access),
Expression::Rand(ident, index) => {
// TODO: replace Rand with BindingAccess in parser?
// TODO: replace Rand with SymbolAccess in parser?
let access_type = AccessType::Vector(index);
let access = BindingAccess::new(ident, access_type);
let access = SymbolAccess::new(ident, access_type);
self.insert_symbol_access(access)
}
Expression::ListFolding(lf_type) => self.insert_list_folding(lf_type),
Expand Down Expand Up @@ -137,19 +137,19 @@ impl ConstraintBuilder {
/// type.
fn insert_symbol_access(
&mut self,
binding_access: BindingAccess,
symbol_access: SymbolAccess,
) -> Result<NodeIndex, SemanticError> {
let symbol = self.symbol_table.get_symbol(binding_access.name())?;
let symbol = self.symbol_table.get_symbol(symbol_access.name())?;

match symbol.symbol_type() {
SymbolType::VariableBinding(bound_value) => {
match symbol.binding() {
SymbolBinding::Variable(bound_value) => {
// access the expression bound to the variable and return an expression that reduces
// to a single element.
let expr = get_variable_expr(bound_value, binding_access)?;
let expr = get_variable_expr(bound_value, symbol_access)?;
self.insert_expr(expr)
}
_ => {
let (_, access_type) = binding_access.into_parts();
let (_, access_type) = symbol_access.into_parts();
// all other symbol types indicate we're accessing a value or group of values.
let value = symbol.get_value(access_type)?;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{
AccessType, BTreeMap, BindingAccess, ConstraintBuilder, Expression, Identifier, Iterable,
ListComprehension, ListFolding, ListFoldingValueExpr, SemanticError, Symbol, SymbolType,
AccessType, BTreeMap, ConstraintBuilder, Expression, Identifier, Iterable, ListComprehension,
ListFolding, ListFoldingValueExpr, SemanticError, Symbol, SymbolAccess, SymbolBinding,
TraceAccess, TraceBindingAccess, TraceBindingAccessSize, VariableValueExpr, CURRENT_ROW,
};

Expand Down Expand Up @@ -44,8 +44,8 @@ impl ConstraintBuilder {
i: usize,
) -> Result<Expression, SemanticError> {
match expression {
Expression::BindingAccess(binding_access) => {
self.parse_elem(binding_access.ident(), iterable_context, i)
Expression::SymbolAccess(symbol_access) => {
self.parse_elem(symbol_access.ident(), iterable_context, i)
}
Expression::TraceBindingAccess(named_trace_access) => {
self.parse_named_trace_access(named_trace_access, iterable_context, i)
Expand Down Expand Up @@ -81,11 +81,9 @@ impl ConstraintBuilder {
/// - Returns an error if the iterable is an identifier and that identifier does not correspond to
/// a vector.
/// - Returns an error if the iterable is an identifier but is not of a type in set:
/// { TraceBinding, IntegrityVariable, PublicInput, RandomValuesBinding }.
/// { Trace, Variable, PublicInput, RandomValues }.
/// - Returns an error if the iterable is a slice and that identifier does not correspond to
/// a vector.
/// - Returns an error if the iterable is an identifier but is not of a type in set:
/// { TraceBinding, IntegrityVariable, PublicInput, RandomValuesBinding }.
fn parse_elem(
&self,
ident: &Identifier,
Expand All @@ -96,7 +94,7 @@ impl ConstraintBuilder {
match iterable {
// if the corresponding iterable is not present in the iterable context that means the
// identifier is not part of the list comprehension and we just return it as it is.
None => Ok(Expression::BindingAccess(BindingAccess::new(
None => Ok(Expression::SymbolAccess(SymbolAccess::new(
ident.clone(),
AccessType::Default,
))),
Expand Down Expand Up @@ -136,8 +134,8 @@ impl ConstraintBuilder {
Some(iterable_type) => match iterable_type {
Iterable::Identifier(ident) => {
let symbol = self.symbol_table.get_symbol(ident.name())?;
match symbol.symbol_type() {
SymbolType::TraceBinding(size) => {
match symbol.binding() {
SymbolBinding::Trace(size) => {
validate_access(i, size.size())?;
Ok(Expression::TraceBindingAccess(TraceBindingAccess::new(
ident.clone(),
Expand All @@ -157,8 +155,8 @@ impl ConstraintBuilder {
))),
Iterable::Slice(ident, range) => {
let symbol = self.symbol_table.get_symbol(ident.name())?;
match symbol.symbol_type() {
SymbolType::TraceBinding(trace_columns) => {
match symbol.binding() {
SymbolBinding::Trace(trace_columns) => {
validate_access(i, trace_columns.size())?;
Ok(Expression::TraceBindingAccess(TraceBindingAccess::new(
ident.clone(),
Expand Down Expand Up @@ -236,24 +234,24 @@ impl ConstraintBuilder {
/// - Returns an error if the iterable identifier is anything other than a vector in the symbol
/// table if it's a variable.
/// - Returns an error if the iterable is not of type in set:
/// { IntegrityVariable, PublicInput, TraceBinding }
/// { Variable, PublicInput, Trace }
fn get_iterable_len(&self, iterable: &Iterable) -> Result<usize, SemanticError> {
match iterable {
Iterable::Identifier(ident) => {
let symbol = self.symbol_table.get_symbol(ident.name())?;
match symbol.symbol_type() {
SymbolType::VariableBinding(variable_type) => match variable_type {
match symbol.binding() {
SymbolBinding::Variable(variable_type) => match variable_type {
VariableValueExpr::Vector(vector) => Ok(vector.len()),
_ => Err(SemanticError::InvalidListComprehension(format!(
"VariableBinding {} should be a vector for a valid list comprehension.",
symbol.name()
))),
},
SymbolType::PublicInput(size) => Ok(*size),
SymbolType::TraceBinding(trace_columns) => Ok(trace_columns.size()),
SymbolBinding::PublicInput(size) => Ok(*size),
SymbolBinding::Trace(trace_columns) => Ok(trace_columns.size()),
_ => Err(SemanticError::InvalidListComprehension(format!(
"SymbolType {} not supported for list comprehensions",
symbol.symbol_type()
"SymbolBinding {} not supported for list comprehensions",
symbol.binding()
))),
}
}
Expand Down Expand Up @@ -300,12 +298,12 @@ fn build_iterable_context(lc: &ListComprehension) -> Result<IterableContext, Sem
///
/// # Errors
/// - Returns an error if the identifier is not of type in set:
/// { IntegrityVariable, PublicInput, TraceBinding, RandomValuesBinding }
/// { Variable, PublicInput, Trace, RandomValues }
/// - Returns an error if the access index is greater than the size of the vector.
/// - Returns an error if the identifier is not a vector in the symbol table if it's a variable.
fn build_ident_expression(symbol: &Symbol, i: usize) -> Result<Expression, SemanticError> {
match symbol.symbol_type() {
SymbolType::TraceBinding(trace_columns) => {
match symbol.binding() {
SymbolBinding::Trace(trace_columns) => {
validate_access(i, trace_columns.size())?;
let trace_segment = trace_columns.trace_segment();
Ok(Expression::TraceAccess(TraceAccess::new(
Expand All @@ -315,7 +313,7 @@ fn build_ident_expression(symbol: &Symbol, i: usize) -> Result<Expression, Seman
CURRENT_ROW,
)))
}
SymbolType::VariableBinding(variable_type) => {
SymbolBinding::Variable(variable_type) => {
match variable_type {
VariableValueExpr::Vector(vector) => {
validate_access(i, vector.len())?;
Expand All @@ -328,12 +326,12 @@ fn build_ident_expression(symbol: &Symbol, i: usize) -> Result<Expression, Seman
)))?,
}
}
SymbolType::PublicInput(size) | SymbolType::RandomValuesBinding(_, size) => {
SymbolBinding::PublicInput(size) | SymbolBinding::RandomValues(_, size) => {
validate_access(i, *size)?;
let access_type = AccessType::Vector(i);
let binding_access =
BindingAccess::new(Identifier(symbol.name().to_string()), access_type);
Ok(Expression::BindingAccess(binding_access))
let symbol_access =
SymbolAccess::new(Identifier(symbol.name().to_string()), access_type);
Ok(Expression::SymbolAccess(symbol_access))
}
_ => Err(SemanticError::InvalidListComprehension(
"{ident_type} is an invalid type for a vector".to_string(),
Expand All @@ -345,16 +343,16 @@ fn build_ident_expression(symbol: &Symbol, i: usize) -> Result<Expression, Seman
///
/// # Errors
/// - Returns an error if the identifier is not of type in set:
/// { IntegrityVariable, PublicInput, TraceBinding, RandomValuesBinding }
/// { Variable, PublicInput, Trace, RandomValues }
/// - Returns an error if the access index is greater than the size of the vector.
/// - Returns an error if the identifier is not a vector in the symbol table if it's a variable.
fn build_slice_ident_expression(
symbol: &Symbol,
range_start: usize,
i: usize,
) -> Result<Expression, SemanticError> {
match symbol.symbol_type() {
SymbolType::TraceBinding(trace_columns) => {
match symbol.binding() {
SymbolBinding::Trace(trace_columns) => {
validate_access(i, trace_columns.size())?;
Ok(Expression::TraceBindingAccess(TraceBindingAccess::new(
Identifier(symbol.name().to_string()),
Expand All @@ -363,7 +361,7 @@ fn build_slice_ident_expression(
CURRENT_ROW,
)))
}
SymbolType::VariableBinding(variable) => {
SymbolBinding::Variable(variable) => {
match variable {
VariableValueExpr::Vector(vector) => {
validate_access(i, vector.len())?;
Expand All @@ -376,12 +374,12 @@ fn build_slice_ident_expression(
)))?,
}
}
SymbolType::PublicInput(size) | SymbolType::RandomValuesBinding(_, size) => {
SymbolBinding::PublicInput(size) | SymbolBinding::RandomValues(_, size) => {
validate_access(i, *size)?;
let access_type = AccessType::Vector(range_start + i);
let binding_access =
BindingAccess::new(Identifier(symbol.name().to_string()), access_type);
Ok(Expression::BindingAccess(binding_access))
let symbol_access =
SymbolAccess::new(Identifier(symbol.name().to_string()), access_type);
Ok(Expression::SymbolAccess(symbol_access))
}
_ => Err(SemanticError::InvalidListComprehension(
"{ident_type} is an invalid type for a vector".to_string(),
Expand Down
16 changes: 8 additions & 8 deletions ir/src/constraint_builder/integrity_constraints/list_folding.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{
ConstantValueExpr, ConstraintBuilder, Expression, ListFoldingValueExpr, SemanticError,
SymbolType, TraceAccess, VariableValueExpr, CURRENT_ROW,
SymbolBinding, TraceAccess, VariableValueExpr, CURRENT_ROW,
};

// LIST FOLDING
Expand All @@ -21,21 +21,21 @@ impl ConstraintBuilder {
match lf_value_type {
ListFoldingValueExpr::Identifier(ident) => {
let symbol = self.symbol_table.get_symbol(ident.name())?;
match symbol.symbol_type() {
SymbolType::ConstantBinding(ConstantValueExpr::Vector(list)) => {
match symbol.binding() {
SymbolBinding::Constant(ConstantValueExpr::Vector(list)) => {
Ok(list.iter().map(|value| Expression::Const(*value)).collect())
}
SymbolType::VariableBinding(variable_type) => {
SymbolBinding::Variable(variable_type) => {
if let VariableValueExpr::Vector(list) = variable_type {
Ok(list.clone())
} else {
Err(SemanticError::invalid_list_folding(
lf_value_type,
symbol.symbol_type(),
symbol.binding(),
))
}
}
SymbolType::TraceBinding(columns) => {
SymbolBinding::Trace(columns) => {
if columns.size() > 1 {
let trace_segment = columns.trace_segment();
Ok((0..columns.size())
Expand All @@ -51,13 +51,13 @@ impl ConstraintBuilder {
} else {
Err(SemanticError::invalid_list_folding(
lf_value_type,
symbol.symbol_type(),
symbol.binding(),
))
}
}
_ => Err(SemanticError::invalid_list_folding(
lf_value_type,
symbol.symbol_type(),
symbol.binding(),
)),
}
}
Expand Down
6 changes: 3 additions & 3 deletions ir/src/constraint_builder/integrity_constraints/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::{
ast::{ConstraintType, IntegrityStmt},
AccessType, BTreeMap, BindingAccess, ConstantValueExpr, ConstraintBuilder, ConstraintDomain,
Expression, Identifier, Iterable, ListComprehension, ListFolding, ListFoldingValueExpr,
SemanticError, Symbol, SymbolType, TraceAccess, TraceBindingAccess, TraceBindingAccessSize,
AccessType, BTreeMap, ConstantValueExpr, ConstraintBuilder, ConstraintDomain, Expression,
Identifier, Iterable, ListComprehension, ListFolding, ListFoldingValueExpr, SemanticError,
Symbol, SymbolAccess, SymbolBinding, TraceAccess, TraceBindingAccess, TraceBindingAccessSize,
VariableBinding, VariableValueExpr, CURRENT_ROW,
};

Expand Down
8 changes: 4 additions & 4 deletions ir/src/constraint_builder/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::{
ast, AccessType, AlgebraicGraph, BTreeMap, BTreeSet, BindingAccess, ConstantValueExpr,
ConstraintDomain, ConstraintRoot, Constraints, Declarations, Expression, Identifier, Iterable,
ListComprehension, ListFolding, ListFoldingValueExpr, NodeIndex, Operation, SemanticError,
Symbol, SymbolTable, SymbolType, TraceAccess, TraceBindingAccess, TraceBindingAccessSize,
ast, AccessType, AlgebraicGraph, BTreeMap, BTreeSet, ConstantValueExpr, ConstraintDomain,
ConstraintRoot, Constraints, Declarations, Expression, Identifier, Iterable, ListComprehension,
ListFolding, ListFoldingValueExpr, NodeIndex, Operation, SemanticError, Symbol, SymbolAccess,
SymbolBinding, SymbolTable, TraceAccess, TraceBindingAccess, TraceBindingAccessSize,
TraceSegment, Value, VariableBinding, VariableValueExpr, CURRENT_ROW,
};

Expand Down
Loading

0 comments on commit e06adfb

Please sign in to comment.