Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl From<CircOpt> for CircCfg {
fn from(opt: CircOpt) -> Self {
let field = if !opt.field.custom_modulus.is_empty() {
let error =
|r: &str| panic!("The field modulus '{}' is {}", &opt.field.custom_modulus, r);
|r: &str| panic!("The field modulus '{}' is {}", opt.field.custom_modulus, r);
let i = Integer::from_str_radix(&opt.field.custom_modulus, 10)
.unwrap_or_else(|_| error("not an integer"));
if i.is_probably_prime(30) == rug::integer::IsPrime::No {
Expand Down
2 changes: 1 addition & 1 deletion src/front/datalog/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ impl<'ast> Gen<'ast> {
let mut bug_in_rule_if_any = Vec::new();
for cond in &rule.conds {
let mut bug_conditions = Vec::new();
debug!("Start case: {}", &rule.name.value);
debug!("Start case: {}", rule.name.value);
self.circ.enter_scope();
if let Some(decls) = cond.existential.as_ref() {
for d in &decls.declarations {
Expand Down
52 changes: 23 additions & 29 deletions src/front/zsharp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn const_bool_simple(t: T) -> Option<bool> {
fn const_val_simple(a: T) -> Result<T, String> {
match const_value_simple(&a.term) {
Some(v) => Ok(T::new(a.ty, leaf_term(Op::new_const(v)))),
_ => Err(format!("{} is not a constant value", &a)),
_ => Err(format!("{} is not a constant value", a)),
}
}

Expand Down Expand Up @@ -741,9 +741,9 @@ impl<'ast> ZGen<'ast> {
let f = self
.functions
.get(&f_path)
.ok_or_else(|| format!("No file '{:?}' attempting fn call", &f_path))?
.ok_or_else(|| format!("No file '{:?}' attempting fn call", f_path))?
.get(&f_name)
.ok_or_else(|| format!("No function '{}' attempting fn call", &f_name))?;
.ok_or_else(|| format!("No function '{}' attempting fn call", f_name))?;
let arg_tys = args.iter().map(|arg| arg.type_().clone());
let generics = ZGenericInf::<IS_CNST>::new(self, f, &f_path, &f_name)
.unify_generic(egv, exp_ty, arg_tys)?;
Expand Down Expand Up @@ -780,7 +780,7 @@ impl<'ast> ZGen<'ast> {
};
let dur = (time::Instant::now() - before).as_millis();
if dur > 50 {
info!("{} ms to process {} {:?}", dur, &f_name, &f_path);
info!("{} ms to process {} {:?}", dur, f_name, f_path);
}
ret
}
Expand All @@ -802,7 +802,7 @@ impl<'ast> ZGen<'ast> {
generics.remove(&gid.value).ok_or_else(|| {
format!(
"Failed to find generic argument {} for builtin call {}",
&gid.value, &f_name,
gid.value, f_name,
)
})
})
Expand All @@ -814,15 +814,15 @@ impl<'ast> ZGen<'ast> {
if f.generics.len() != generics.len() {
return Err(format!(
"Wrong number of generic params calling {} (got {}, expected {})",
&f.id.value,
f.id.value,
generics.len(),
f.generics.len()
));
}
if f.parameters.len() != args.len() {
return Err(format!(
"Wrong nimber of arguments calling {} (got {}, expected {})",
&f.id.value,
f.id.value,
args.len(),
f.parameters.len()
));
Expand Down Expand Up @@ -940,7 +940,7 @@ impl<'ast> ZGen<'ast> {
} else {
panic!(
"No function '{:?}//{}' attempting const_entry_fn",
&f_file, &f_name
f_file, f_name
)
}
}
Expand All @@ -952,9 +952,9 @@ impl<'ast> ZGen<'ast> {
let f = self
.functions
.get(&f_file)
.unwrap_or_else(|| panic!("No file '{:?}'", &f_file))
.unwrap_or_else(|| panic!("No file '{:?}'", f_file))
.get(&f_name)
.unwrap_or_else(|| panic!("No function '{}'", &f_name))
.unwrap_or_else(|| panic!("No function '{}'", f_name))
.clone();
// XXX(unimpl) tuple returns not supported
assert!(f.returns.len() <= 1);
Expand Down Expand Up @@ -1195,7 +1195,7 @@ impl<'ast> ZGen<'ast> {
None if IS_CNST => self.cvar_lookup(&i.value).ok_or_else(|| {
format!(
"Undefined const identifier {} in {}",
&i.value,
i.value,
self.cur_path().to_string_lossy()
)
}),
Expand All @@ -1204,7 +1204,7 @@ impl<'ast> ZGen<'ast> {
.map_err(|e| format!("{e}"))?
{
Val::Term(t) => Ok(t),
_ => Err(format!("Non-Term identifier {}", &i.value)),
_ => Err(format!("Non-Term identifier {}", i.value)),
},
}
}
Expand Down Expand Up @@ -1338,13 +1338,7 @@ impl<'ast> ZGen<'ast> {
assert!(!p.accesses.is_empty());
let (val, accs) = if let Some(ast::Access::Call(c)) = p.accesses.first() {
let (f_path, f_name) = self.deref_import(&p.id.value);
let exp_ty = self.lhs_ty_take().and_then(|ty| {
if p.accesses.len() > 1 {
None
} else {
Some(ty)
}
});
let exp_ty = self.lhs_ty_take().filter(|_ty| p.accesses.len() <= 1);
let args = c
.arguments
.expressions
Expand Down Expand Up @@ -1640,7 +1634,7 @@ impl<'ast> ZGen<'ast> {
.search(&sa.id.value)
.map(|r| r.1.clone())
.ok_or_else(|| {
format!("No such member {} of struct {nm}", &sa.id.value)
format!("No such member {} of struct {nm}", sa.id.value)
}),
ty => Err(format!("Attempted member access on non-Struct type {ty}")),
},
Expand Down Expand Up @@ -1783,7 +1777,7 @@ impl<'ast> ZGen<'ast> {
.unwrap_or(false)
{
self.err(
format!("Constant {} clashes with import of same name", &c.id.value),
format!("Constant {} clashes with import of same name", c.id.value),
&c.span,
);
}
Expand Down Expand Up @@ -1816,7 +1810,7 @@ impl<'ast> ZGen<'ast> {

if let Some(ast::ArrayParamMetadata::Transcript(_)) = &c.array_metadata {
if !value.type_().is_array() {
self.err(format!("Non-array transcript {}", &c.id.value), &c.span);
self.err(format!("Non-array transcript {}", c.id.value), &c.span);
}
self.mark_array_as_transcript(&c.id.value, value.clone());
}
Expand All @@ -1829,7 +1823,7 @@ impl<'ast> ZGen<'ast> {
.insert(c.id.value.clone(), (c.ty.clone(), value))
.is_some()
{
self.err(format!("Constant {} redefined", &c.id.value), &c.span);
self.err(format!("Constant {} redefined", c.id.value), &c.span);
}
}

Expand Down Expand Up @@ -1869,7 +1863,7 @@ impl<'ast> ZGen<'ast> {
let (def, path) = self.get_struct_or_type(&s.id.value).ok_or_else(|| {
format!(
"No such struct {} (did you bring it into scope?)",
&s.id.value
s.id.value
)
})?;
let generics = match def {
Expand All @@ -1886,7 +1880,7 @@ impl<'ast> ZGen<'ast> {
if generics.len() != g_len {
return Err(format!(
"Struct {} is not monomorphized or wrong number of generic parameters",
&s.id.value
s.id.value
));
}
self.file_stack_push(path);
Expand Down Expand Up @@ -2086,7 +2080,7 @@ impl<'ast> ZGen<'ast> {
.is_some()
{
self.err(
format!("Struct {} defined over existing name", &s.id.value),
format!("Struct {} defined over existing name", s.id.value),
&s.span,
);
}
Expand All @@ -2111,7 +2105,7 @@ impl<'ast> ZGen<'ast> {
.is_some()
{
self.err(
format!("Type {} defined over existing name", &t.id.value),
format!("Type {} defined over existing name", t.id.value),
&t.span,
);
}
Expand All @@ -2132,7 +2126,7 @@ impl<'ast> ZGen<'ast> {
self.err(
format!(
"Functions must return exactly 1 value; {} returns {}",
&f_ast.id.value,
f_ast.id.value,
f_ast.returns.len(),
),
&f.span,
Expand Down Expand Up @@ -2164,7 +2158,7 @@ impl<'ast> ZGen<'ast> {
.insert(f.id.value.clone(), f_ast)
.is_some()
{
self.err(format!("Function {} redefined", &f.id.value), &f.span);
self.err(format!("Function {} redefined", f.id.value), &f.span);
}
}
ast::SymbolDeclaration::Import(_) => (), // already handled in visit_imports
Expand Down
10 changes: 5 additions & 5 deletions src/front/zsharp/term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ pub fn const_fold(t: T) -> T {
pub fn const_val(a: T) -> Result<T, String> {
match const_value(&a.term) {
Some(v) => Ok(T::new(a.ty, const_(v))),
_ => Err(format!("{} is not a constant value", &a)),
_ => Err(format!("{} is not a constant value", a)),
}
}

Expand Down Expand Up @@ -917,7 +917,7 @@ fn coerce_to_field(i: T) -> Result<Term, String> {
match &i.ty {
Ty::Uint(_) => Ok(to_dflt_f(i.term)),
Ty::Field => Ok(i.term),
_ => Err(format!("Cannot coerce {} to a field element", &i)),
_ => Err(format!("Cannot coerce {} to a field element", i)),
}
}

Expand All @@ -931,7 +931,7 @@ pub fn array_select(array: T, idx: T) -> Result<T, String> {
let iterm = coerce_to_field(idx).unwrap();
Ok(T::new(Ty::Field, term![Op::Select; array.term, iterm]))
}
_ => Err(format!("Cannot index {} using {}", &array.ty, &idx.ty)),
_ => Err(format!("Cannot index {} using {}", array.ty, idx.ty)),
}
}

Expand Down Expand Up @@ -959,7 +959,7 @@ pub fn array_store(array: T, idx: T, val: T) -> Result<T, String> {
term![Op::Store; array.term, iterm, val.term],
))
} else {
Err(format!("Cannot index {} using {}", &array.ty, &idx.ty))
Err(format!("Cannot index {} using {}", array.ty, idx.ty))
}
}

Expand Down Expand Up @@ -1120,7 +1120,7 @@ pub fn bit_array_le(a: T, b: T, n: usize) -> Result<T, String> {
Ok(())
}
}
_ => Err(format!("Cannot do bit-array-le on ({}, {})", &a.ty, &b.ty)),
_ => Err(format!("Cannot do bit-array-le on ({}, {})", a.ty, b.ty)),
}?;

let at = bv_from_bits(a.term, n);
Expand Down
6 changes: 3 additions & 3 deletions src/front/zsharp/zvisit/eqtype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn eq_array_type<'ast>(
(Struct(sty), Struct(sty2)) => eq_struct_type(sty, sty2, zgen),
_ => Err(ZVisitorError(format!(
"array type mismatch: \n\texpected elms of type {:?}, \n\tfound {:?}",
&ty.ty, &ty2.ty,
ty.ty, ty2.ty,
))),
}
}
Expand All @@ -71,7 +71,7 @@ fn eq_struct_type<'ast>(
// neither ty nor ty2 is a type alias, so they are really different
Err(ZVisitorError(format!(
"struct type mismatch: \n\texpected {:?}, \n\tfound {:?}",
&ty.id.value, &ty2.id.value,
ty.id.value, ty2.id.value,
)))
} else {
eq_type(&canon_type(ty, zgen)?, &canon_type(ty2, zgen)?, zgen)
Expand All @@ -97,7 +97,7 @@ fn canon_type<'ast>(ty: &ast::StructType<'ast>, zgen: &ZGen<'ast>) -> ZResult<as
.ok_or_else(|| {
ZVisitorError(format!(
"eqtype: unknown struct or type alias {}",
&ty.id.value
ty.id.value
))
})
}
6 changes: 3 additions & 3 deletions src/front/zsharp/zvisit/zconstlitrw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl<'ast> ZVisitorMut<'ast> for ZConstLiteralRewriter {
let ty_map = if let Some(t) = to_ty.as_ref() {
if let Ty::Struct(name, ty_map) = t {
if name != &ise.ty.value {
Err(format!("ZConstLiteralRewriter: got struct {}, expected {} visiting inline struct expression", &ise.ty.value, name))
Err(format!("ZConstLiteralRewriter: got struct {}, expected {} visiting inline struct expression", ise.ty.value, name))
} else {
Ok(Some(ty_map.clone()))
}
Expand All @@ -190,7 +190,7 @@ impl<'ast> ZVisitorMut<'ast> for ZConstLiteralRewriter {
.remove(&m.id.value)
.ok_or_else(|| ZVisitorError(format!(
"ZConstLiteralRewriter: no member {} in struct {}, or duplicate member in inline expression",
&m.id.value,
m.id.value,
str_name,
)))
.and_then(|ty| {
Expand All @@ -202,7 +202,7 @@ impl<'ast> ZVisitorMut<'ast> for ZConstLiteralRewriter {
if !ty_map.is_empty() {
return Err(format!(
"ZConstLiteralRewriter: inline expression for struct {} has extra fields: {:?}",
&ise.ty.value,
ise.ty.value,
ty_map.keys().collect::<Vec<_>>(),
)
.into());
Expand Down
20 changes: 10 additions & 10 deletions src/front/zsharp/zvisit/zgenericinf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl<'ast, 'gen, const IS_CNST: bool> ZGenericInf<'ast, 'gen, IS_CNST> {
Ty::Uint(32) => Ok(v.term),
ty => Err(format!(
"ZGenericInf: ConstantGenericValue for {} had type {}, expected u32",
&id.value, ty
id.value, ty
)),
}?;
self.add_constraint(var, val);
Expand All @@ -135,7 +135,7 @@ impl<'ast, 'gen, const IS_CNST: bool> ZGenericInf<'ast, 'gen, IS_CNST> {
(Some(rty), Some(ret)) => self.fdef_gen_ty(rty, ret),
(Some(rty), None) if rty != Ty::Bool => Err(format!(
"Function {} expected implicit Bool ret, but got {}",
&self.fdef.id.value, rty
self.fdef.id.value, rty
)),
(Some(_), None) => Ok(()),
(None, _) => Ok(()),
Expand All @@ -155,7 +155,7 @@ impl<'ast, 'gen, const IS_CNST: bool> ZGenericInf<'ast, 'gen, IS_CNST> {
{
assert!(self.gens.len() == res.len());
assert!(self.gens.iter().all(|g| res.contains_key(&g.value)));
debug!("done (cached result for {})", &self.sfx);
debug!("done (cached result for {})", self.sfx);
return Ok(res);
}
let g_names = self
Expand Down Expand Up @@ -285,7 +285,7 @@ impl<'ast, 'gen, const IS_CNST: bool> ZGenericInf<'ast, 'gen, IS_CNST> {
let (stdef, stpath) = self
.zgen
.get_struct_or_type(&def_ty.id.value)
.ok_or_else(|| format!("ZGenericInf: no struct struct or type {}", &def_ty.id.value))?;
.ok_or_else(|| format!("ZGenericInf: no struct struct or type {}", def_ty.id.value))?;
let generics = match &stdef {
Ok(strdef) => &strdef.generics[..],
Err(tydef) => &tydef.generics[..],
Expand All @@ -296,7 +296,7 @@ impl<'ast, 'gen, const IS_CNST: bool> ZGenericInf<'ast, 'gen, IS_CNST> {
return if def_ty.explicit_generics.is_some() {
Err(format!(
"Unifying generics: got explicit generics for non-generic struct type {}:\n{}",
&def_ty.id.value,
def_ty.id.value,
span_to_string(&def_ty.span),
))
} else {
Expand All @@ -314,8 +314,8 @@ impl<'ast, 'gen, const IS_CNST: bool> ZGenericInf<'ast, 'gen, IS_CNST> {
{
return Err(format!(
"Cannot infer generic values for struct {} arg to function {}\nGeneric structs in fn defns must have explicit generics (in terms of fn generic vars)",
&def_ty.id.value,
&self.fdef.id.value,
def_ty.id.value,
self.fdef.id.value,
));
}

Expand Down Expand Up @@ -358,7 +358,7 @@ impl<'ast, 'gen, const IS_CNST: bool> ZGenericInf<'ast, 'gen, IS_CNST> {
}
Ty::Struct(aty_n, _) => Err(format!(
"Type mismatch: got struct {aty_n}, decl was struct {}",
&def_ty.id.value
def_ty.id.value
)),
arg_ty => Err(format!(
"Type mismatch unifying generics: got {arg_ty}, decl was Struct",
Expand All @@ -370,14 +370,14 @@ impl<'ast, 'gen, const IS_CNST: bool> ZGenericInf<'ast, 'gen, IS_CNST> {
} else {
return Err(format!(
"ZGenericInf: missing member {} in struct {} value",
&id.value, &def_ty.id.value,
id.value, def_ty.id.value,
));
}
}
if !aty_map.is_empty() {
return Err(format!(
"ZGenericInf: struct {} value had extra members: {:?}",
&def_ty.id.value,
def_ty.id.value,
aty_map.keys().collect::<Vec<_>>(),
));
}
Expand Down
Loading
Loading