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

feat: decompose macros feature as macros-decl and macros-proc #4804

Closed
wants to merge 4 commits into from
Closed

feat: decompose macros feature as macros-decl and macros-proc #4804

wants to merge 4 commits into from

Conversation

BastiDood
Copy link

Motivation

As its name suggests, the macros feature enables the use of various macros in Tokio. Among the most beloved are the #[tokio::main] and the select! macros.

However, one major difference between attribute macros and declarative macros is that the former requires the tokio-macros crate, which is the home for various procedural macros.

macros = ["tokio-macros"]

In turn, a dependency on the tokio-macros crate also pulls in the (relatively heavy) syn and quote crates.

[dependencies]
proc-macro2 = "1.0.7"
quote = "1"
syn = { version = "1.0.56", features = ["full"] }

The main issue arises when attribute macros are not needed, but the user still wishes to use the declarative macros (i.e. select!, join!, and try_join!). They are thus forced to enable the macros feature, which undesirably pulls in the attribute macros from the tokio-macros crate anyway.

Solution

To avoid this issue, this PR decomposes the macros feature into two sub-features: macros-decl and macros-proc.1 The macros-decl feature enables the declarative macros while the macros-proc feature enables the procedural macros. To maintain backwards-compatibility, the macros feature is now just an alias for ["macros-decl", "macros-proc"].

Most notably, the macros-proc feature enables dep:tokio-macros.2 The explicit decomposition allows the user to use the declarative macros without being forced to pull in the heavier attribute macros.3

Please do let me know if there are any issues with my decomposition. In particular, I would love to resolve any compilation issues (if any) that arise due to outdated references to the old macros feature. Thanks! 🎉

Footnotes

  1. I'm open to changing the sub-feature names if anyone prefers otherwise. I figured that this was an appropriate naming convention since there is already precedent with ["io-std", "io-util"] and ["rt", "rt-multi-thread"].

  2. In the actual PR, I did not use the dep: prefix to respect the MSRV.

  3. It is worth noting, however, that the syn and quote crates would have been pulled in by other crates, anyway. This is especially true for projects with many dependencies (most notably serde_derive). Nevertheless, it is still good to give the user extra control over the compilation of dependencies.

@taiki-e
Copy link
Member

taiki-e commented Jul 2, 2022

Note that the compile of tokio-macros will be fast enough once #4513 is merged.

@BastiDood
Copy link
Author

Looking forward to it! Though, I must say that there is still some value in decomposing the features anyway. This is so that users do not need to download nor compile tokio-macros in the first place. For instance, consider a situation where it is possible for Tokio to compile earlier in the topologically-ordered tree of dependencies by removing tokio-macros (if not needed). A little less work for the compiler goes a long way. 👌

@Darksonn
Copy link
Contributor

Darksonn commented Jul 9, 2022

The select! macro depends on a proc macro.

@Darksonn
Copy link
Contributor

I'm going to close this for now. It's not clear that we want to do this because it exposes implementation details of the tokio::select! macro. Additionally, discussing that kind of stuff should generally happen on an issue rather than a PR.

@Darksonn Darksonn closed this Jul 17, 2022
@gustav3d
Copy link

Note that the compile of tokio-macros will be fast enough once #4513 is merged.

Will it ever be merged ?.

@Darksonn
Copy link
Contributor

Well, it requires that someone sits down and spends the time to figure out what the PR is missing, and then to fix those missing things.

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

4 participants