Skip to content

Commit

Permalink
chore: update string formatting for clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
grjte committed Jan 25, 2023
1 parent ccb90ba commit 5f25642
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 49 deletions.
6 changes: 3 additions & 3 deletions air-script/src/cli/transpile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ impl TranspileCmd {
// parse the input file to the internal representation
let parsed = parse(source.as_str());
if let Err(err) = parsed {
return Err(format!("{:?}", err));
return Err(format!("{err:?}"));
}
let parsed = parsed.unwrap();

let ir = AirIR::from_source(&parsed);
if let Err(err) = ir {
return Err(format!("{:?}", err));
return Err(format!("{err:?}"));
}
let ir = ir.unwrap();

Expand All @@ -69,7 +69,7 @@ impl TranspileCmd {
// write transpiled output to the output path
let result = fs::write(output_path.clone(), codegen.generate());
if let Err(err) = result {
return Err(format!("{:?}", err));
return Err(format!("{err:?}"));
}

println!("Success! Transpiled to {}", output_path.display());
Expand Down
2 changes: 1 addition & 1 deletion air-script/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ pub fn main() {

// execute cli action
if let Err(error) = cli.execute() {
println!("{}", error);
println!("{error}");
}
}
10 changes: 5 additions & 5 deletions codegen/winterfell/src/air/boundary_constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,17 @@ impl Codegen for Expression {
match self {
Self::Const(value) => {
if is_aux_constraint {
format!("E::from({}_u64)", value)
format!("E::from({value}_u64)")
} else {
format!("Felt::new({})", value)
format!("Felt::new({value})")
}
}
// TODO: Check element type and cast accordingly.
Self::Elem(ident) => {
if is_aux_constraint {
format!("E::from({})", ident)
format!("E::from({ident})")
} else {
format!("{}", ident)
format!("{ident}")
}
}
Self::VectorAccess(vector_access) => {
Expand Down Expand Up @@ -143,7 +143,7 @@ impl Codegen for Expression {
}
}
Self::Rand(index) => {
format!("aux_rand_elements.get_segment_elements(0)[{}]", index)
format!("aux_rand_elements.get_segment_elements(0)[{index}]")
}
Self::Add(lhs, rhs) => {
format!(
Expand Down
6 changes: 3 additions & 3 deletions codegen/winterfell/src/air/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ impl Codegen for Constant {
fn to_string(&self) -> String {
match self.value() {
ConstantType::Scalar(scalar_const) => {
format!("Felt::new({})", scalar_const)
format!("Felt::new({scalar_const})")
}
ConstantType::Vector(vector_const) => format!(
"[{}]",
vector_const
.iter()
.map(|val| format!("Felt::new({})", val))
.map(|val| format!("Felt::new({val})"))
.collect::<Vec<String>>()
.join(", ")
),
Expand All @@ -57,7 +57,7 @@ impl Codegen for Constant {
rows.push(format!(
"[{}]",
row.iter()
.map(|val| format!("Felt::new({})", val))
.map(|val| format!("Felt::new({val})"))
.collect::<Vec<String>>()
.join(", "),
))
Expand Down
4 changes: 2 additions & 2 deletions codegen/winterfell/src/air/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn add_air_struct(scope: &mut Scope, ir: &AirIR, name: &str) {

// add public inputs
for (pub_input, pub_input_size) in ir.public_inputs() {
air_struct.field(pub_input, format!("[Felt; {}]", pub_input_size));
air_struct.field(pub_input, format!("[Felt; {pub_input_size}]"));
}

// add the custom Air implementation block
Expand Down Expand Up @@ -157,7 +157,7 @@ let context = AirContext::new_multi_segment(
// get public inputs
let mut pub_inputs = Vec::new();
for (pub_input, _) in ir.public_inputs() {
pub_inputs.push(format!("{}: public_inputs.{}", pub_input, pub_input));
pub_inputs.push(format!("{pub_input}: public_inputs.{pub_input}"));
}
// return initialized Self.
new.line(format!("Self {{ context, {} }}", pub_inputs.join(", ")));
Expand Down
2 changes: 1 addition & 1 deletion codegen/winterfell/src/air/periodic_columns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl Codegen for PeriodicColumns {
for column in self {
let mut rows = vec![];
for row in column {
rows.push(format!("Felt::new({})", row));
rows.push(format!("Felt::new({row})"));
}
columns.push(format!("vec![{}]", rows.join(", ")));
}
Expand Down
9 changes: 3 additions & 6 deletions codegen/winterfell/src/air/public_inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub(super) fn add_public_inputs_struct(scope: &mut Scope, ir: &AirIR) {
let pub_inputs_struct = scope.new_struct(name).vis("pub");

for (pub_input, pub_input_size) in ir.public_inputs() {
pub_inputs_struct.field(pub_input, format!("[Felt; {}]", pub_input_size));
pub_inputs_struct.field(pub_input, format!("[Felt; {pub_input_size}]"));
}

// add the public inputs implementation block
Expand All @@ -27,7 +27,7 @@ pub(super) fn add_public_inputs_struct(scope: &mut Scope, ir: &AirIR) {
.ret("Self")
.line(format!("Self {{ {} }}", pub_inputs_values.join(", ")));
for (pub_input, pub_input_size) in ir.public_inputs() {
new_fn.arg(pub_input, format!("[Felt; {}]", pub_input_size));
new_fn.arg(pub_input, format!("[Felt; {pub_input_size}]"));
}

add_serializable_impl(scope, pub_inputs_values)
Expand All @@ -42,9 +42,6 @@ fn add_serializable_impl(scope: &mut Scope, pub_input_values: Vec<String>) {
.arg_ref_self()
.arg("target", "&mut W");
for pub_input_value in pub_input_values {
write_into_fn.line(format!(
"target.write(self.{}.as_slice());",
pub_input_value
));
write_into_fn.line(format!("target.write(self.{pub_input_value}.as_slice());"));
}
}
18 changes: 9 additions & 9 deletions codegen/winterfell/src/air/transition_constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ impl Codegen for Operation {
// TODO: Only add parentheses in Add and Mul if the expression is an arithmetic operation.
fn to_string(&self, graph: &AlgebraicGraph) -> String {
match self {
Operation::Constant(ConstantValue::Inline(value)) => format!("E::from({}_u64)", value),
Operation::Constant(ConstantValue::Scalar(ident)) => format!("E::from({})", ident),
Operation::Constant(ConstantValue::Inline(value)) => format!("E::from({value}_u64)"),
Operation::Constant(ConstantValue::Scalar(ident)) => format!("E::from({ident})"),
Operation::Constant(ConstantValue::Vector(vector_access)) => {
format!("E::from({}[{}])", vector_access.name(), vector_access.idx())
}
Expand All @@ -102,35 +102,35 @@ impl Codegen for Operation {
_ => panic!("Winterfell doesn't support row offsets greater than 1."),
},
Operation::PeriodicColumn(col_idx, _) => {
format!("periodic_values[{}]", col_idx)
format!("periodic_values[{col_idx}]")
}
Operation::RandomValue(idx) => {
format!("aux_rand_elements.get_segment_elements(0)[{}]", idx)
format!("aux_rand_elements.get_segment_elements(0)[{idx}]")
}
Operation::Neg(idx) => {
let str = idx.to_string(graph);
format!("- ({})", str)
format!("- ({str})")
}
Operation::Add(l_idx, r_idx) => {
let lhs = l_idx.to_string(graph);
let rhs = r_idx.to_string(graph);

format!("{} + {}", lhs, rhs)
format!("{lhs} + {rhs}")
}
Operation::Sub(l_idx, r_idx) => {
let lhs = l_idx.to_string(graph);
let rhs = r_idx.to_string(graph);

format!("{} - ({})", lhs, rhs)
format!("{lhs} - ({rhs})")
}
Operation::Mul(l_idx, r_idx) => {
let lhs = l_idx.to_string(graph);
let rhs = r_idx.to_string(graph);
format!("({}) * ({})", lhs, rhs)
format!("({lhs}) * ({rhs})")
}
Operation::Exp(l_idx, r_idx) => {
let lhs = l_idx.to_string(graph);
format!("({}).exp(E::PositiveInteger::from({}_u64))", lhs, r_idx)
format!("({lhs}).exp(E::PositiveInteger::from({r_idx}_u64))")
}
}
}
Expand Down
9 changes: 2 additions & 7 deletions ir/src/integrity_stmts/degree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,11 @@ impl IntegrityConstraintDegree {
for (i, &cycle) in cycles.iter().enumerate() {
assert!(
cycle >= MIN_CYCLE_LENGTH,
"cycle length must be at least {}, but was {} for cycle {}",
MIN_CYCLE_LENGTH,
cycle,
i
"cycle length must be at least {MIN_CYCLE_LENGTH}, but was {cycle} for cycle {i}"
);
assert!(
cycle.is_power_of_two(),
"cycle length must be a power of two, but was {} for cycle {}",
cycle,
i
"cycle length must be a power of two, but was {cycle} for cycle {i}"
);
}
IntegrityConstraintDegree {
Expand Down
6 changes: 2 additions & 4 deletions ir/src/integrity_stmts/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,12 @@ impl AlgebraicGraph {
}
} else {
Err(SemanticError::InvalidUsage(format!(
"Identifier {} was declared as a {} which is not a supported type.",
ident, elem_type
"Identifier {ident} was declared as a {elem_type} which is not a supported type."
)))
}
}
_ => Err(SemanticError::InvalidUsage(format!(
"Identifier {} was declared as a {} which is not a supported type.",
ident, elem_type
"Identifier {ident} was declared as a {elem_type} which is not a supported type."
))),
}
}
Expand Down
12 changes: 4 additions & 8 deletions ir/src/symbol_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ impl SymbolTable {
.insert(ident_name.to_owned(), ident_type.clone());
match result {
Some(prev_type) => Err(SemanticError::DuplicateIdentifier(format!(
"Cannot declare {} as a {}, since it was already defined as a {}",
ident_name, ident_type, prev_type
"Cannot declare {ident_name} as a {ident_type}, since it was already defined as a {prev_type}"
))),
None => Ok(()),
}
Expand Down Expand Up @@ -191,8 +190,7 @@ impl SymbolTable {
Ok(ident_type)
} else {
Err(SemanticError::InvalidIdentifier(format!(
"Identifier {} was not declared",
name
"Identifier {name} was not declared"
)))
}
}
Expand Down Expand Up @@ -305,15 +303,13 @@ fn validate_cycles(column: &PeriodicColumn) -> Result<(), SemanticError> {

if !cycle.is_power_of_two() {
return Err(SemanticError::InvalidPeriodicColumn(format!(
"cycle length must be a power of two, but was {} for cycle {}",
cycle, name
"cycle length must be a power of two, but was {cycle} for cycle {name}"
)));
}

if cycle < MIN_CYCLE_LENGTH {
return Err(SemanticError::InvalidPeriodicColumn(format!(
"cycle length must be at least {}, but was {} for cycle {}",
MIN_CYCLE_LENGTH, cycle, name
"cycle length must be at least {MIN_CYCLE_LENGTH}, but was {cycle} for cycle {name}"
)));
}

Expand Down

2 comments on commit 5f25642

@Al-Kindi-0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if there is a need for a second review.

@grjte
Copy link
Contributor Author

@grjte grjte commented on 5f25642 Jan 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if there is a need for a second review.

I think it's fine - I just fixed the rustfmt failure. Nothing materially changed. Thanks!

Please sign in to comment.