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 all the Sync and Send trait bounds #2

Merged

Conversation

arnauorriols
Copy link

Trait bounds should generally be pushed to the latest moment when they are actually needed. That is, the functions that manipulate the data and that actually require the bound. It is usually avoided (to the reasonable extend) to put trait bounds in the type parameters of data types and trait declarations, as they unleash an unergonomic "trait bound hell" and are usually overly restrictive.

Some relevant references:

In this case, the trait bounds "Sync" and "Send" are already enforced (if necessary) when the async runtime actually schedule the Futures, and it is at this point (if actually enforced by the runtime) that all the types and intermediate functions that manipulate those types are required to enforce these markers; However, if at any point of the rabbit hole a type bound is placed on the data, hell breaks loose and all types that touch the bounded type get contaminated. Implied bounds RFC might mitigate the issue, but for the time being, this convention is gold one of those that is "all or nothing", because of the "viral" effect.

Trait bounds should generally be pushed to the latest moment when they are actually needed.
That is, the functions that manipulate the data and that actually require the bound.
It is usually avoided (to the reasonable extend) to put trait bounds in the type parameters
of data types and trait declarations, as they unleash an unergonomic "trait bound hell" and are usually overly restrictive.

Some relevant references:
- [API Guidelines]
- [discussion API Guidelines]
- [flat2 case]
- [Haskell Programming Guidelines]

In this case, the trait bounds "Sync" and "Send" are already enforced (if necessary) when the async runtime actually schedule the Futures,
and it is at this point (if actually enforced by the runtime) that all the types and intermediate functions that manipulate those types are required
to enforce these markers; However, if at any point of the rabbit hole a type bound is placed on the data, hell breaks loose and all types that touch
the bounded type get contaminated. [Implied bounds RFC] might mitigate the issue, but for the time being, this convention is gold one of those that
is "all or nothing", because of the "viral" effect.

[API Guidelines]: https://rust-lang.github.io/api-guidelines/future-proofing.html#data-structures-do-not-duplicate-derived-trait-bounds-c-struct-bounds
[discussion API Guidelines]: rust-lang/api-guidelines#6
[Haskell Programming Guidelines]: https://wiki.haskell.org/Programming_guidelines#Types
[flate2 case]: rust-lang/flate2-rs#88
[Implied bounds RFC]: rust-lang/rust#44491
@DyrellC DyrellC merged commit 59c8df2 into DyrellC:feat/remove-async-flag Sep 3, 2021
DyrellC pushed a commit that referenced this pull request Oct 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants