-
Notifications
You must be signed in to change notification settings - Fork 499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better error handling for AssignedCell value queries #509
Comments
There's only one part which I'm unsure which is the desired behavior. This change means that APIs like But I'm not sure if this is the desired behavior for you. |
Something that would help a lot would be to be able to make usage of With this the API for impl<F: FieldExt> Var<F> for AssignedCell<F, F> {
fn cell(&self) -> Cell {
self.cell()
}
fn value(&self) -> Result<F, Error> {
self.value().cloned()
}
} While now needs quite some work as: impl<F: FieldExt> Var<F> for AssignedCell<F, F> {
fn cell(&self) -> Cell {
self.cell()
}
fn value(&self) -> Result<F, Error> {
self.value().and_then(|val| Ok(val.to_owned()))
}
} Was stabilized not so long ago and marked for release 1.59. |
Returning let a = foo.value();
let b = bar.value();
let c = a.zip(b).map(|(a, b)| a + b); you'd need let a = foo.value();
let b = bar.value();
let c = a.and_then(|a| b.map(|b| a + b)); which is both more complex (nested closures, which doesn't look too bad in this contrived example but would quickly get out of hand), and forces the user to make a judgement call about which value's error is more important. It is also a non-starter because this is a type error: during witness synthesis we don't want to expose an let a = foo.value()?;
let b = bar.value()?;
let c = a + b; and breaks their code, because we can't raise those errors except inside the value closure of a I think what we instead need to do (I've described this to people at various times, but appear to have not written it down yet) is introduce a custom let a = foo.value();
let b = bar.value();
let c = a + b; i.e. it should Just Work for common operations, while providing a trapdoor that exposes the underlying |
I implemented my proposed |
Sorry @str4d . I've been extremely bussy lately. Having a kid soon, so can't really invest the time I wanted on this. Will take a look to the PR! Thanks a lot for working on this! 😄 |
I've been working with/reviewing the
AssignedCell
API. And there's one thing that it's a bit annoying.When you need the value of the
Cell
as V, you can callAssignedCell::value
, and that's great.The problem is that it returns an
Option<V>
which then requires to do something like.ok_or_else(ERR_HANDLING)?;
After discussing with @therealyingtong different aproaches, like
MaybeUninit
etc.. I suggested one that seemed to be Ok:After that, the suggested err variant was
Error::Synthesis
.I think that would help in cases where we need to do some extra stuff with the value and we don't want to end up with a bunch of
ok_or_else
or unwraps/expects in the code.The text was updated successfully, but these errors were encountered: