Commit bf64fac
committed
Merge rust-bitcoin/rust-miniscript#722: Eliminate a bunch more recursion; expand the
d0c0c14ae26e353c950319182fd853ee90b8eb54 miniscript: nonrecursive implementation of PartialEq/Eq/Hash (Andrew Poelstra)
117003f3d1c89129734288153a870abb7e940e45 miniscript: implement PartialOrd/Ord nonrecursively (Andrew Poelstra)
cccaaec8bc189f5dcf8212c40d0f752ce90d9063 miniscript: non-recursive Display implementation (Andrew Poelstra)
47bed0c281aaf67cba19eb4b7feda86e464b29cb iter: get rid of Arc::clones and allocations for n-ary nodes (Andrew Poelstra)
67d6ff78ad044ab0048e796e376529b6d2be9191 iter: introduce Ternary variant (Andrew Poelstra)
Pull request description:
This PR replaces the recursive derived implementations of `PartialEq`, `PartialOrd`, `Hash`, `fmt::Debug` and `fmt::Display`. Along the way it expands the `iter::TreeLike` trait to make it a bit more useful (adding a `Ternary` variant and making the existing `Nary` variant generic as long as you can get a length out of it and index into it).
The new `fmt::Debug` method works using a new `DisplayNode` wrapper around `Terminal` which allows iterating over a script in the same way as it's displayed, treating things like `or_i(0, X)` as `l:X` and implementing the `c:pk_k` aliases and so on. This seems generally useful but this PR does not expose it in the public API because I'd like to make some breaking changes to `Terminal` down the line and don't want to expand the API.
The new `Ord` impl orders things alphabetically (assuming it is bug-free at least) by using the same iterator as the display logic. This is both nonrecursive and a more useful ordering for anybody who cares about the exact ordering. On the other hand, if anybody is depending on the *existing* ordering this will break their code. I would assume not, since the existing ordering is a weird ad-hoc thing based on the order that `derive(PartialOrd)` happens to use.
Similarly, it adds a `Terminal::fragment_name` accessor which returns a `&'static str` representing the fragment name as displayed. This is also not put into the public API.
The block of type parameters used in the debug output of Miniscripts is moved into a `fmt::Display` impl on `Type` itself. This is part of the public API.
This PR does **not** replace the `Clone` impl, which is currently derived. This impl actually isn't recursive, since it just clones the `Arc`s in the first layer of the script. Maybe we want to implement this manually and do a "deep copy"? This would be useful for users who have keys with interior mutability or something. I have a followup which does this, but didn't include it because I felt it might be controversial and need its own discussion.
This PR also does **not** replace the implicit `Drop` impl, because that's hard to do and I haven't done it. But we're making progress.
ACKs for top commit:
sanket1729:
ACK d0c0c14ae26e353c950319182fd853ee90b8eb54.
Tree-SHA512: edc42b5ed7d2b562e93d3c061328c2020f710534a5cad3878b849d900d697be4919232e1f1c178fdc5338bd2e6ef71ebcfed90b2b8b8e577d8f781d887771bc1TreeLike iterator trait a bitFile tree
9 files changed
+622
-272
lines changed- src
- iter
- miniscript
- types
- policy
9 files changed
+622
-272
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
22 | 27 | | |
23 | 28 | | |
24 | 29 | | |
| |||
36 | 41 | | |
37 | 42 | | |
38 | 43 | | |
39 | | - | |
40 | | - | |
| 44 | + | |
| 45 | + | |
41 | 46 | | |
42 | 47 | | |
43 | 48 | | |
44 | 49 | | |
45 | | - | |
46 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
47 | 57 | | |
48 | 58 | | |
49 | 59 | | |
| |||
54 | 64 | | |
55 | 65 | | |
56 | 66 | | |
57 | | - | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
58 | 98 | | |
59 | 99 | | |
60 | 100 | | |
61 | 101 | | |
62 | 102 | | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
68 | 106 | | |
69 | 107 | | |
70 | 108 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | 10 | | |
12 | 11 | | |
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
16 | | - | |
| 15 | + | |
17 | 16 | | |
18 | 17 | | |
19 | 18 | | |
20 | 19 | | |
21 | 20 | | |
22 | 21 | | |
| 22 | + | |
| 23 | + | |
23 | 24 | | |
24 | | - | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
38 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
39 | 53 | | |
40 | | - | |
| 54 | + | |
41 | 55 | | |
42 | 56 | | |
43 | 57 | | |
44 | 58 | | |
45 | 59 | | |
46 | 60 | | |
47 | 61 | | |
48 | | - | |
| 62 | + | |
| 63 | + | |
49 | 64 | | |
50 | 65 | | |
51 | 66 | | |
| |||
58 | 73 | | |
59 | 74 | | |
60 | 75 | | |
61 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
62 | 84 | | |
63 | 85 | | |
64 | 86 | | |
| |||
210 | 232 | | |
211 | 233 | | |
212 | 234 | | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
213 | 240 | | |
214 | | - | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
215 | 244 | | |
216 | 245 | | |
217 | 246 | | |
| |||
0 commit comments