refactor: make stricter database trait bounds for user ergonomics#1840
refactor: make stricter database trait bounds for user ergonomics#1840prestwich wants to merge 4 commits intobluealloy:mainfrom
Conversation
|
hmmmm. for some reason it seems not all packages build when running punting to draft |
|
Ok it seems to be mostly an example that was broken, so I've updated that :) I think this is ready for consideration. CI failure appears to be unrelated |
| #[auto_impl(&mut, Box)] | ||
| pub trait State { | ||
| type Error; | ||
| type Error: core::error::Error + 'static; |
There was a problem hiding this comment.
in this case, it's required by the impl :Error for DatabaseComponentError<T, U> here. The bound could be removed here, but it would require all downstream users to propagate 2 bounds every time they want to use that impl Error for DatabaseComponentError (which is pretty often in practice)
Given that we don't have any examples of errors borrowing (i.e. all our current databases would meet this bound) it seems pretty reasonble to put it here too. This is just an example lib, and I don't feel strongly about its ergonomics tho
I would consider adding a + 'static bound to the Error assoc type in trait Database tho, for the same reason. We have no clear use case for errors that capture data instead of own it, and it causes a lot of downstream complexity
|
|
||
| /// Wraps a [`BlockHashRef`] to provide a [`BlockHash`] implementation. | ||
| #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
| pub struct WrapBlockHashRef<T: BlockHashRef>(pub T); |
There was a problem hiding this comment.
hm, i can't remember it but would this code
impl<T: BlockHashRef> BlockHash for T {
solve all of this
There was a problem hiding this comment.
it was unnecessary anyway so i removed it
| pub trait Database { | ||
| /// The database error type. | ||
| type Error; | ||
| type Error: core::error::Error; |
There was a problem hiding this comment.
I would consider adding a 'static bound here, as described in https://github.com/bluealloy/revm/pull/1840/files#r1819000225
| pub trait DatabaseRef { | ||
| /// The database error type. | ||
| type Error; | ||
| type Error: core::error::Error; |
There was a problem hiding this comment.
I would consider adding a 'static bound here, as described in https://github.com/bluealloy/revm/pull/1840/files#r1819000225
| pub trait DatabaseAsync { | ||
| /// The database error type. | ||
| type Error: Send; | ||
| type Error: core::error::Error + Send; |
There was a problem hiding this comment.
I would consider adding a 'static bound here, as described in https://github.com/bluealloy/revm/pull/1840/files#r1819000225
| pub trait DatabaseAsyncRef { | ||
| /// The database error type. | ||
| type Error: Send; | ||
| type Error: core::error::Error + Send; |
There was a problem hiding this comment.
I would consider adding a 'static bound here, as described in https://github.com/bluealloy/revm/pull/1840/files#r1819000225
a14a377 to
c44063b
Compare
|
CI failure seems to be related to #1844 |
|
closing as stale, may eventually resubmit |
Two quick ergonomics changes for downstream users. Intended to simplify bounds writing
This is a breaking change, as downstream implementors of these traits may need to be updated
Errorbounds for database errorsAdds an error bound for
Database::ErrorandDatabaseRef::Error, and the async versions. This closes #1674. This prevents propagation of complex bounds for upstream wrapper structs, particularly error types that might wrap EVM output.motivation:
simplify bounds writing for users by ensuring they don't need to manually write out error bounds. This is particulartly a problem when holding an instance of
EVMError<Db>Before:
After:
Add
Databaseas a supertrait ofDatabaseCommitThis does not close a current issue, but I'm happy to make one. This causes some bounds changes in the
database_componentsexamplesmotivation: simplify bounds writing for users by allowing them to avoid specifying
Databasealternate approach: a
trait CommitableDatabase: Database + DatabaseCommitwith a blanketimpl<T> CommittableDatabase for T where T: Database + DatabaseCommitCode before:
Code after:
Add
WrapBlockHashRefto exampleAdd a wrapper struct like
WrapDatabaseReftoBlockHashRefto allow relaxing the bounds on the database components in thedatabase_componentsexampleDrive-by:
The asyncdb is cfged out when running
cargo c --all-features. And runningcargo c -p revm-database-interface --features asyncdbproduced compilation errors due to disabled tokio features. I have enabled the necessary features. When running with--workspaceit appears some other package enabled the features, and covered up the dep specification issue