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

Adopt dynamic trait object upcasting once released in Rust #284

Open
Tracked by #303
Wodann opened this issue Feb 5, 2024 · 3 comments
Open
Tracked by #303

Adopt dynamic trait object upcasting once released in Rust #284

Wodann opened this issue Feb 5, 2024 · 3 comments

Comments

@Wodann
Copy link
Member

Wodann commented Feb 5, 2024

Rust has historically not been natively capable of upcasting dynamic trait objects to sub-traits. Work has been culminating to a beta that we expect should be released in the upcoming year.

To circumvent this limitation in Rust, EDR uses super-traits throughout the codebase, while we would like to be more restrictive. Once it's possible to upcast a super-trait to it sub-trait, we should restrict function signatures to the sub-traits

Definition of Done
Wherever possible, limit usages of SyncBlockchain, SyncBlock, SyncState, SyncLogger, and SyncInspector in function signatures to their sub-traits

@jwbda
Copy link
Contributor

jwbda commented Mar 14, 2024

Hi, Wodann, thanks for the hard work. I'm very interested in what you're doing, but I can't understand your code of rust. Can you explain a little bit about what problem you are solving or share relevant information for learning. Thank you very much.

@Wodann
Copy link
Member Author

Wodann commented Mar 14, 2024

Thank you! 🙏

As we allow runtime polymorphism for our blockchains, state, and blocks (local vs remote), we need to use dynamic trait objects. We're using super-traits in our codebase to specify the complete set of traits that such a runtime polymorphic object needs.

However, some of our dependencies, in particular revm need a subset of traits. Currently, upcasting of a super-trait dynamic object to the sub-trait is not supported in Rust.

However, a correction of the memory layout that would add support for this is in the works. It was supposed to be released with Rust v1.76.0, but issues were discovered and the feature removed.

This task is meant to remove unnecessary usages of the super-trait dynamic object when it suffices to only support the sub-trait

@jwbda
Copy link
Contributor

jwbda commented Apr 7, 2024

Thanks for the detaied explanation. @Wodann

@fvictorio fvictorio moved this from Todo to Blocked in EDR Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Blocked
Development

No branches or pull requests

3 participants