-
Notifications
You must be signed in to change notification settings - Fork 141
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
Remove recursion in semantic
module
#612
Remove recursion in semantic
module
#612
Conversation
803424f
to
79f9583
Compare
Needs #613 |
6ab8308
to
9507538
Compare
Ooooo, the first two cleanup patches should not technically be part of this PR because I never ended up being able to do |
@@ -415,9 +415,11 @@ impl<Pk: MiniscriptKey> Policy<Pk> { | |||
|
|||
let n = subs.len() - unsatisfied_count - trivial_count; // remove all true/false | |||
let m = k.checked_sub(trivial_count).map_or(0, |x| x); // satisfy all trivial | |||
// m == n denotes `and` and m == 1 denotes `or` | |||
|
|||
// m == n denotes `and` and m == 1 denotes `or` | |||
let is_and = m == n; | |||
let is_or = m == 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In 939695d:
We can just delete this comment I think. I can't imagine what value it provides beyond the code itself.
src/policy/semantic.rs
Outdated
@@ -380,7 +380,7 @@ impl_from_tree!( | |||
// thresh(1) and thresh(n) are disallowed in semantic policies | |||
if thresh <= 1 || thresh >= (nsubs as u32 - 1) { | |||
return Err(errstr( | |||
"Semantic Policy thresh cannot have k = 1 or k =n, use `and`/`or` instead", | |||
"Semantic Policy thresh cannot have k=1 or k==n, use `and`/`or` instead", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In 939695d:
I think single equality was fine, but I don't feel strongly about it. But you need to the same = operator in both cases :).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol, its hard to get good help. Just added the space into the original line. I've been chided recently about doing trivial patches and slowing the dev process down, this is definitely a case of that :(
cc @Kixunil - woops.
src/policy/mod.rs
Outdated
subs.iter().map(|s| s.node.lift()).collect(); | ||
let semantic_subs = semantic_subs? | ||
.into_iter() | ||
.map(|sub| Arc::new(sub)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In 9de17fc:
This map should just be map(Arc::new)
. (Though I assume you're going to remove this in a later commit, since otherwise clippy would've complained about it.) Same in many other cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't run clippy in CI :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed them all, I think.
ae6975e
to
e85b046
Compare
81055a4
to
333bfb4
Compare
Rebased and removed the |
cbbc582 onward does not compile after the rebase. |
|
@tcharding just
Same error with |
Bizarre, I rebased and ran cargo on each commit. Will re-try today. |
80b8e2c
to
0421aef
Compare
Had to rebase to fix merge conflicts. Corrected the removal of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 0421aef
@tcharding Sorry for the long absence, I can review this after a rebase. |
Remove unnecessary code comment, the local variables names are clear enough.
This function is fiendishly hard to understand, add a line of whitespace as a tiny baby step towards making it clearer.
Currently we are using `map_or` in a convoluted manner, we can just use `unwrap_or` to get the inner value or default to 0. Refactor only, no logic changes.
We have a little typo in an error string, fix it up.
Use standard from for import statements. (Note `Arc` is already in scope in `super`.)
0421aef
to
14ec788
Compare
When we implemented the `TreeLike` trait for the concrete `Policy` we put it in the `iter` module, it doesn't really live there, better to put the impl in the same place as the definition of the implementor. Move the impl of `TreeLike` for `concrete::Policy` to the `concrete` module.
In preparation for removing recursive algorithms in the `semantic` module add an `Arc` wrapper around the policies in the `Thresh` vector. Note we use the more explicit `Arc::new` instead of `into` because a lot of these should be removed when we remove recursion, later it may be necessary to check that we are not creating new references when a clone will suffice, the explicit `Arc::new` is easier to check. In tests however just use `into`.
In preparation for removing recursive algorithms in the `semantic` module implement the `TreeLike` trait to enable iteration over policy nodes. This is a direct copy of the `concrete::Policy` impl with the `And` and `Or` variants removed.
Done as part of the effort to remove all the recursion crate wide. Use the `TreeLike` trait to iterate over policy nodes and remove the recursive call in `semantic::Policy::for_each_key`.
Done as part of the effort to remove all the recursion crate wide. Use the `TreeLike` trait to iterate over policy nodes and remove the recursive call in `semantic::Policy::translate_pk`.
Done as part of the effort to remove all the recursion crate wide. Use the `TreeLike` trait to iterate over policy nodes and remove the recursive call in `semantic::Policy::n_terminals`.
Done as part of the effort to remove all the recursion crate wide. Use the `TreeLike` trait to iterate over policy nodes and remove the recursive call in the `semantic::Policy::real_*_timelocks` functions. Done together because they are basically identical.
Done as part of the effort to remove all the recursion crate wide. Use the `TreeLike` trait to iterate over policy nodes and remove the recursive call in `semantic::Policy::at_age` and `semantic::Policy::at_age`. Done together because they are basically identical.
Done as part of the effort to remove all the recursion crate wide. Use the `TreeLike` trait to iterate over policy nodes and remove the recursive call in `semantic::Policy::n_keys`.
Done as part of the effort to remove all the recursion crate wide. Use the `TreeLike` trait to iterate over policy nodes and remove the recursive call in `semantic::Policy::minimum_n_keys`.
Done as part of the effort to remove all the recursion crate wide. Use the `TreeLike` trait to iterate over policy nodes and remove the recursive call in `semantic::Policy::sorted`.
14ec788
to
f9307c8
Compare
@sanket1729! Good to have you back. Rebased, no changes required. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK f9307c8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK f9307c8
Remove most of the recursion in the
semantic
module. Does not donormalized
and associated functions (ones that either call it or take in a normalized policy).Includes 4 trivial preparatory clean up patches at the front.