Closed gio54321 closed 1 month ago
Great investigation!
Yes, indeed this is a bug. I think the solution can be changing the GenericSizedArray
to the concrete type Array
when propagating the type during type checking phase.
ExprKind::RepeatedArrayInit { item, size } => {
let item_node = self
.compute_type(item, typed_fn_env)?
.expect("expected a typed item");
let size_node = self
.compute_type(size, typed_fn_env)?
.expect("expected a typed size");
if is_numeric(&size_node.typ) {
// use generic array as the size node might include generic parameters or constant vars
let res = ExprTyInfo::new_anon(TyKind::GenericSizedArray(
Box::new(item_node.typ),
Symbolic::parse_expr(size)?,
));
Some(res)
} else {
return Err(self.error(ErrorKind::InvalidArraySize, expr.span));
}
}
After parsing the size
expression from Symbolic
, we can check if it is a concrete variant. If it is concrete, then instead it should return
let res = ExprTyInfo::new_anon(TyKind::Array(
Box::new(item_node.typ),
size,
));
Some(res)
created a fix pr: https://github.com/zksecurity/noname/pull/187
I was trying to write this simple circuit
But, trying to compile it, gives back a panic in circuit writer
After a bit of debugging, the problem is that the lhs of the assignment
still has type
GenericSizedArray(Field { constant: true }, Concrete(3))
, which should not happen since we are in the circuit writer component.I think the main issue here is that the body of the function
sum_arr
is not monomorphized, since functions are monomorphized only if needed. Debugging the code,fn_info.sig().require_monomorphization()
returns False (which makes sense as the function signature does not contain any generic-sized array), so the function body AST is left as is and passed to the circuit writer component. However the AST contains theGenericSizedArray
objects because of the generic sized arrayresult
declared inside the function.