Crate cleanups#110
Conversation
Eirik0
left a comment
There was a problem hiding this comment.
Everything looks great! The only thing I have not reviewed is the addition of log = "0.4".
There was a problem hiding this comment.
Is there a benefit to dereferencing here? I am wondering if this is not necessary, as of Rust 1.26: https://rust-lang.github.io/rfcs/2005-match-ergonomics.html
There was a problem hiding this comment.
The clippy warning that this change addressed is:
warning: you don't need to add `&` to all patterns
--> bellman/src/gadgets/boolean.rs:415:9
|
415 | / match self {
416 | | &Boolean::Constant(c) => Some(c),
417 | | &Boolean::Is(ref v) => v.get_value(),
418 | | &Boolean::Not(ref v) => v.get_value().map(|b| !b),
419 | | }
| |_________^
|
= note: #[warn(clippy::match_ref_pats)] on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_ref_pats
help: instead of prefixing all patterns with `&`, you can dereference the expression
|
415 | match *self {
416 | Boolean::Constant(c) => Some(c),
417 | Boolean::Is(ref v) => v.get_value(),
418 | Boolean::Not(ref v) => v.get_value().map(|b| !b),
|
Dereferencing is still necessary here:
$ git diff
diff --git a/bellman/src/gadgets/boolean.rs b/bellman/src/gadgets/boolean.rs
index b26bb19..dafa82f 100644
--- a/bellman/src/gadgets/boolean.rs
+++ b/bellman/src/gadgets/boolean.rs
@@ -412,7 +412,7 @@ impl Boolean {
}
pub fn get_value(&self) -> Option<bool> {
- match *self {
+ match self {
Boolean::Constant(c) => Some(c),
Boolean::Is(ref v) => v.get_value(),
Boolean::Not(ref v) => v.get_value().map(|b| !b),
$ cargo build
Compiling bellman v0.1.0 (/.../librustzcash/bellman)
error[E0308]: mismatched types
--> bellman/src/gadgets/boolean.rs:416:42
|
416 | Boolean::Constant(c) => Some(c),
| ^
| |
| expected bool, found &bool
| help: consider dereferencing the borrow: `*c`
|
= note: expected type `bool`
found type `&bool`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.
error: Could not compile `bellman`.
To learn more, run the command again with --verbose.
$ rustc --version
rustc 1.36.0 (a53f9df32 2019-07-03)
There was a problem hiding this comment.
Is there a distinction between to_bits_ and into_bits_? I am comparing this to the name change in bellman/src/gadgets/num.rs.
There was a problem hiding this comment.
The clippy warning that this change addresses is:
warning: methods called `into_*` usually take self by value; consider choosing a less ambiguous name
--> bellman/src/gadgets/uint32.rs:78:25
|
78 | pub fn into_bits_be(&self) -> Vec<Boolean> {
| ^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#wrong_self_convention
This follows the corresponding entry in the Rust style guide.
I altered the various methods to be consistent with how they used self in context. I first tried having the into_* methods consume self, and where that was not possible due to the caller relying on passing an immutable reference, I altered the method name to to_*.
There was a problem hiding this comment.
This change is also made when running cargo fix --edition-idioms.
There was a problem hiding this comment.
This could be replaced with
// Mask away the unused most-significant bits.
let tmp = Fs(FsRepr([
rng.next_u64(),
rng.next_u64(),
rng.next_u64(),
rng.next_u64() & (0xffffffffffffffff >> REPR_SHAVE_BITS),
]));
And then we wouldn't need the loop below, but that may be beyond the scope of this PR.
|
I added |
|
Looking good, will re-review when #113 is merged since it will conflict with this I think. |
Memo::from_str was previously shadowing a built-in trait method.
|
Rebased on master to fix merge conflicts with #113. |
Eirik0
left a comment
There was a problem hiding this comment.
utACK. Rebase looks good.
defuse
left a comment
There was a problem hiding this comment.
utACK. I left some non-blocking comments.
| let mut delta = E::Fr::one(); | ||
| { | ||
| let mut tmp = params.montgomery_a().clone(); | ||
| let mut tmp = *params.montgomery_a(); |
There was a problem hiding this comment.
Rust noob question: Is it correct that I can be sure this isn't modifying any part of params because it isn't &mut in the function signature? (I've been making this assumption in a couple cases above where an explicit .clone() was removed, too.).
There was a problem hiding this comment.
JubjubParams::montgomery_a takes &self, so you are guarateed that params is not modified.
The reason for removing the clone() is that JubjubParams::montgomery_a returns JubjubEngine::Fr (which resolves to ff::ScalarEngine::Fr), which via ff::Field is required to implement Copy, and thus makes the explicit clone unnecessary.
|
|
||
| let mut elt = E::Fr::one(); | ||
| for i in 0..(1 << log_new_n) { | ||
| for (i, tmp) in tmp.iter_mut().enumerate() { |
There was a problem hiding this comment.
Previously this loop's body would execute 1 << log_new_n times. With this change it should execute num_cpus times according to the length of tmp when it's created above, right?. Won't that change the behavior?
Oh, I see tmp, is shadowed by the outermost loop so here it will have length 1 << log_new_n and the behavior is unchanged. It might be worth renaming some variables to avoid similar confusion.
The voting flow showed an infinite spinner when initialization failed (e.g. vote server unreachable, network error) because initializeFailed silently did nothing, leaving the screen stuck on .loading. Add error and wallet-syncing screens: - .error screen with retry/dismiss when init throws - .walletSyncing screen when wallet hasn't synced to snapshot height - Reset to .loading on retry so re-initialization works Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
No description provided.