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

add back support for inner attributes on non-block expressions? #84879

Closed
nikomatsakis opened this issue May 3, 2021 · 7 comments · Fixed by #86821
Closed

add back support for inner attributes on non-block expressions? #84879

nikomatsakis opened this issue May 3, 2021 · 7 comments · Fixed by #86821
Labels
P-critical Critical priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Milestone

Comments

@nikomatsakis
Copy link
Contributor

nikomatsakis commented May 3, 2021

In #83312, @petrochenkov proposed the removal of inner attributes on non-block expressions. In the 2021-04-27 meeting, the @rust-lang/lang team noted a few concerns, but I didn't get around to raising those concerns on the PR itself before it was merged. I'm opening this issue to capture subsequent discussion.

The heart of the @rust-lang/lang concerns was that these attributes are in fact supported on stable and arguably working as expected. Some of us in the meeting felt like we would expect these attributes to be supported and that -- given that they are accepted -- there is only one potential interpretation (the current one). Plus we know that some crates (admittedly, not many) are using them.

Therefore, we would like to understand better the motivation for removing parser support for these features. The primary given motivation was parser performance, but on the PR thread @Aaron1011 suggested this was no longer a relevant concern.

@nikomatsakis nikomatsakis added I-nominated T-lang Relevant to the language team, which will review and decide on the PR/issue. labels May 3, 2021
@Mark-Simulacrum
Copy link
Member

One thing that I had brought up during the lang team discussion, though not a concern shared by others I think, is that the meaning of the inner attribute can be somewhat ambiguous in expression positions (e.g., tuples). I don't think this merits a straight removal but we had discussed this point and I think I wasn't able to communicate my point too well, and was asked to write up a comment.

When we have a tuple like (#![foo] 3, 5) the foo attribute applies to the tuple per the current semantics. One could argue, however, that this is not necessarily the only possibility: it could equally apply to the "first element expression", i.e., the 3, if the elements are viewed as little contexts of their own. This is likely not the semantics most would expect, so it's a minor concern, but it's possible there are contexts where this is less "obviously not the semantic", I suppose.

@nikomatsakis
Copy link
Contributor Author

Thanks @Mark-Simulacrum. I understand the point you're raising better now, although I still think the current usage feels pretty unambiguous.

It's also worth noting that the fact that these attributes work on stable is due to a bug:

Feature gating for attributes on expressions and statements is exceptionally random and buggy. As a result some of the inner attributes in question are also available on stable in some cases (the attribute must be a built-in, and the expression must be an expression statement).

@nikomatsakis
Copy link
Contributor Author

Actually, reading @Aaron1011's comment more closely:

Note that in the final approach taken in #82608, inner attributes on expressions are now less of a problem than they once were. Custom inner attributes in expressions are banned, so we only need to pessimize token collection in the presence of #[derive] or #[cfg_attr]. However, there are still performance wins to be had in these cases, and the performance issue would likely become significant again if we decided to perform cfg-stripping for all attribute macros (in addition to derive macros).

I see that the current code works in part by detecting built-in attributes. That sounds unfortunate. I think I'm inclined to let the revert stand at present. We can always add these features back if desired.

@nikomatsakis
Copy link
Contributor Author

We discussed this in our @rust-lang/lang meeting today! There wasn't a firm consensus, but we were concerned about the fact that we regressed 4 crates and about the fact that we failed to register a concern. However, the concerns raised in the PR are valid and there was no sense that supporting (#![foo] ..) and so forth was necessary (even if it does have some potential use in removing ambiguity). It would also be possible to add back in.

The meeting ended with us moving towards the option of adding back in inner attributes on match expressions specifically, since that covers all known breakage. @pnkfelix mentioned that they might prepare a PR, but @petrochenkov or @Aaron1011 can you speak to the potential performance impact of such a move?

@pnkfelix
Copy link
Member

I believe this is addressed by PR #85193

@Mark-Simulacrum Mark-Simulacrum added P-critical Critical priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed I-nominated T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Jun 22, 2021
@joshtriplett
Copy link
Member

joshtriplett commented Jun 22, 2021

We discussed this in the @rust-lang/lang meeting today. Our conclusion was that we can close this issue as soon as #85193 is merged. That PR addresses the observed regressions.

@pnkfelix pnkfelix reopened this Jun 24, 2021
@pnkfelix
Copy link
Member

(close this after #85193 gets a beta backport)

@cuviper cuviper linked a pull request Jul 2, 2021 that will close this issue
@jyn514 jyn514 closed this as completed Jul 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P-critical Critical priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants