Skip to content
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::Policy::normalized #614

Draft
wants to merge 21 commits into
base: master
Choose a base branch
from

Commits on Oct 17, 2023

  1. Remove code comment

    Remove unnecessary code comment, the local variables names are clear enough.
    tcharding committed Oct 17, 2023
    Configuration menu
    Copy the full SHA
    67c0a1a View commit details
    Browse the repository at this point in the history
  2. Add line of whitespace

    This function is fiendishly hard to understand, add a line of whitespace
    as a tiny baby step towards making it clearer.
    tcharding committed Oct 17, 2023
    Configuration menu
    Copy the full SHA
    3401747 View commit details
    Browse the repository at this point in the history
  3. Use unwrap_or

    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.
    tcharding committed Oct 17, 2023
    Configuration menu
    Copy the full SHA
    f764508 View commit details
    Browse the repository at this point in the history
  4. Improve spacing in error string

    We have a little typo in an error string, fix it up.
    tcharding committed Oct 17, 2023
    Configuration menu
    Copy the full SHA
    4043ce5 View commit details
    Browse the repository at this point in the history
  5. Fix imports in test module

    Use standard from for import statements. (Note `Arc` is already in scope
    in `super`.)
    tcharding committed Oct 17, 2023
    Configuration menu
    Copy the full SHA
    7b561da View commit details
    Browse the repository at this point in the history
  6. Move TreeLike impl to concrete module

    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.
    tcharding committed Oct 17, 2023
    Configuration menu
    Copy the full SHA
    3592e9b View commit details
    Browse the repository at this point in the history
  7. Add Arc to the semantic::Policy::Thresh vector

    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`.
    tcharding committed Oct 17, 2023
    Configuration menu
    Copy the full SHA
    2017942 View commit details
    Browse the repository at this point in the history
  8. Implement TreeLike for semantic::Policy

    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.
    tcharding committed Oct 17, 2023
    Configuration menu
    Copy the full SHA
    8bfb717 View commit details
    Browse the repository at this point in the history
  9. semantic: Remove recursion in 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::for_each_key`.
    tcharding committed Oct 17, 2023
    Configuration menu
    Copy the full SHA
    10011db View commit details
    Browse the repository at this point in the history
  10. semantic: Remove recursion in 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::translate_pk`.
    tcharding committed Oct 17, 2023
    Configuration menu
    Copy the full SHA
    10a77fa View commit details
    Browse the repository at this point in the history
  11. semantic: Remove recursion in 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 `semantic::Policy::n_terminals`.
    tcharding committed Oct 17, 2023
    Configuration menu
    Copy the full SHA
    48a0af8 View commit details
    Browse the repository at this point in the history
  12. semantic: Remove recursion in real_*_timelocks

    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.
    tcharding committed Oct 17, 2023
    Configuration menu
    Copy the full SHA
    2c422e6 View commit details
    Browse the repository at this point in the history
  13. semantic: Remove recursion in at_age and at_lock_time

    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.
    tcharding committed Oct 17, 2023
    Configuration menu
    Copy the full SHA
    1d536cb View commit details
    Browse the repository at this point in the history
  14. semantic: Remove recursion in 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::n_keys`.
    tcharding committed Oct 17, 2023
    Configuration menu
    Copy the full SHA
    ef98b6b View commit details
    Browse the repository at this point in the history
  15. semantic: Remove recursion in 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::minimum_n_keys`.
    tcharding committed Oct 17, 2023
    Configuration menu
    Copy the full SHA
    e890d8f View commit details
    Browse the repository at this point in the history
  16. semantic: Remove recursion in sorted

    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`.
    tcharding committed Oct 17, 2023
    Configuration menu
    Copy the full SHA
    0421aef View commit details
    Browse the repository at this point in the history
  17. Add unit tests for normalized

    The `semantic::Policy::normalized` function is recursive and has nested
    processing of `Threshold`s. It is not trivial to fully grok.
    
    The function is already tested elsewhere in the unit tests but we don't
    have simple single purpose tests for it.
    
    Add various unit tests for `normalized`, these serve as documentation of
    the function as much as anything.
    tcharding committed Oct 17, 2023
    Configuration menu
    Copy the full SHA
    285214e View commit details
    Browse the repository at this point in the history
  18. Clone sub instead of creating new Arc

    Currently we are creating a new `Arc<Policy::Threshold>` from the pieces
    of `sub` that we pattern matched on. We can just clone the original
    `sub` instead.
    tcharding committed Oct 17, 2023
    Configuration menu
    Copy the full SHA
    d3d4564 View commit details
    Browse the repository at this point in the history
  19. Refactor to use parent/child notation

    In `normalized` we process the threshold policy as well as its child
    threshold policy and we shadow `subs` - this is all very confusing. Add
    parent/child terminology and a couple extra local variables in an
    attempt to make the code more clear.
    
    Refactor only, no logic changes.
    tcharding committed Oct 17, 2023
    Configuration menu
    Copy the full SHA
    2c3d41d View commit details
    Browse the repository at this point in the history
  20. Pull the (m, n) calculation out into sub function

    The `normalize` function spans more than a screen (on my monitor), as
    such it is hard to work on.
    
    Refactor out the (m, n)-thresh calculation to a function so that the
    body of the function becomes shorter.
    
    Refactor only, no logic changes.
    tcharding committed Oct 17, 2023
    Configuration menu
    Copy the full SHA
    6449f38 View commit details
    Browse the repository at this point in the history
  21. Remove recursion in normalized

    Remove the recursive call in `semantic::Policy::normalized`, using
    the `TreeLike` trait to iterate nodes instead.
    tcharding committed Oct 17, 2023
    Configuration menu
    Copy the full SHA
    1f0486b View commit details
    Browse the repository at this point in the history