-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge #650: Replace macros with traits; other cleanups
164bde9 miniscript: add parsing benchmarks (Andrew Poelstra) bbafc39 expression: add parsing benchmark (Andrew Poelstra) 30d2d11 miniscript: factor out a couple parts of Terminal::from_tree (Andrew Poelstra) f22dc3a miniscript: use new TRUE/FALSE constants throughout the codebase (Andrew Poelstra) be41d8b miniscript: add constants for 1 and 0 (Andrew Poelstra) 270e65d Replace macros with blanket impls (Andrew Poelstra) 5ec0f44 add `blanket_traits` module to replace very noisy trait definitions (Andrew Poelstra) Pull request description: There are several macros we use to implement functions when our `Pk` types satisfy a large bundle of trait conditions. There is a trick rust-lang/rust#20671 (comment) that we can use instead. While I'm at it, do several other small cleanups. As a weekend project I rewrote the expression module and was able to get a 10-15% speedup on parsing miniscripts, while eliminating recursion and simplifying the algorithms. I am still working on cleaning up the code and improving the error handling. This is the first set of commits from that branch, which should be simple and uncontroversial. ACKs for top commit: apoelstra: > ACK [164bde9](164bde9). Are you taking a performance refactor stab at rust-miniscript? sanket1729: ACK 164bde9. Are you taking a performance refactor stab at rust-miniscript? Tree-SHA512: 42e11f5f45fa705e14334e79126a66c97577fc6e807f804beaa1532bf3693a6c41a8b714bc4d1436209a1e0d808dc6a3ccc7198f20ff467f40f12126d1ee02f3
- Loading branch information
Showing
20 changed files
with
397 additions
and
377 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// SPDX-License-Identifier: CC0-1.0 | ||
|
||
//! Blanket Traits | ||
//! | ||
//! Because of this library's heavy use of generics, we often require complicated | ||
//! trait bounds (especially when it comes to [`FromStr`] and its | ||
//! associated error types). These blanket traits act as aliases, allowing easier | ||
//! descriptions of them. | ||
//! | ||
//! While these traits are not sealed, they have blanket-impls which prevent you | ||
//! from directly implementing them on your own types. The traits will be | ||
//! automatically implemented if you satisfy all the bounds. | ||
//! | ||
|
||
use core::fmt; | ||
use core::str::FromStr; | ||
|
||
use crate::MiniscriptKey; | ||
|
||
/// Blanket trait describing a key where all associated types implement `FromStr`, | ||
/// and all `FromStr` errors can be displayed. | ||
pub trait FromStrKey: | ||
MiniscriptKey< | ||
Sha256 = Self::_Sha256, | ||
Hash256 = Self::_Hash256, | ||
Ripemd160 = Self::_Ripemd160, | ||
Hash160 = Self::_Hash160, | ||
> + FromStr<Err = Self::_FromStrErr> | ||
{ | ||
/// Dummy type. Do not use. | ||
type _Sha256: FromStr<Err = Self::_Sha256FromStrErr>; | ||
/// Dummy type. Do not use. | ||
type _Sha256FromStrErr: fmt::Debug + fmt::Display; | ||
/// Dummy type. Do not use. | ||
type _Hash256: FromStr<Err = Self::_Hash256FromStrErr>; | ||
/// Dummy type. Do not use. | ||
type _Hash256FromStrErr: fmt::Debug + fmt::Display; | ||
/// Dummy type. Do not use. | ||
type _Ripemd160: FromStr<Err = Self::_Ripemd160FromStrErr>; | ||
/// Dummy type. Do not use. | ||
type _Ripemd160FromStrErr: fmt::Debug + fmt::Display; | ||
/// Dummy type. Do not use. | ||
type _Hash160: FromStr<Err = Self::_Hash160FromStrErr>; | ||
/// Dummy type. Do not use. | ||
type _Hash160FromStrErr: fmt::Debug + fmt::Display; | ||
/// Dummy type. Do not use. | ||
type _FromStrErr: fmt::Debug + fmt::Display; | ||
} | ||
|
||
impl<T> FromStrKey for T | ||
where | ||
Self: MiniscriptKey + FromStr, | ||
<Self as MiniscriptKey>::Sha256: FromStr, | ||
Self::Hash256: FromStr, | ||
Self::Ripemd160: FromStr, | ||
Self::Hash160: FromStr, | ||
<Self as FromStr>::Err: fmt::Debug + fmt::Display, | ||
<<Self as MiniscriptKey>::Sha256 as FromStr>::Err: fmt::Debug + fmt::Display, | ||
<Self::Hash256 as FromStr>::Err: fmt::Debug + fmt::Display, | ||
<Self::Ripemd160 as FromStr>::Err: fmt::Debug + fmt::Display, | ||
<Self::Hash160 as FromStr>::Err: fmt::Debug + fmt::Display, | ||
{ | ||
type _Sha256 = <T as MiniscriptKey>::Sha256; | ||
type _Sha256FromStrErr = <<T as MiniscriptKey>::Sha256 as FromStr>::Err; | ||
type _Hash256 = <T as MiniscriptKey>::Hash256; | ||
type _Hash256FromStrErr = <<T as MiniscriptKey>::Hash256 as FromStr>::Err; | ||
type _Ripemd160 = <T as MiniscriptKey>::Ripemd160; | ||
type _Ripemd160FromStrErr = <<T as MiniscriptKey>::Ripemd160 as FromStr>::Err; | ||
type _Hash160 = <T as MiniscriptKey>::Hash160; | ||
type _Hash160FromStrErr = <<T as MiniscriptKey>::Hash160 as FromStr>::Err; | ||
type _FromStrErr = <T as FromStr>::Err; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.