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

optimize attribute applied to things other than methods/functions/c… #128943

Closed

Conversation

Borgerr
Copy link
Contributor

@Borgerr Borgerr commented Aug 10, 2024

…losures gives an error (#128488)

Relevant issues:

PR changes attribute to only apply to functions, methods, and closures by failing compilation rather than giving a warning. This relates back to this relevant comment.

This PR should absolutely be merged only after a consensus by those with say over the RFC. The purpose of the PR is to allow a simple button press for accomplishing the task.

Cc. @Centril @clubby789 @oli-obk
r? rust-lang/diagnostics

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 10, 2024
@jieyouxu
Copy link
Member

jieyouxu commented Aug 11, 2024

r? @jieyouxu

This needs a T-lang FCP since it diverges from the original RFC 2412 specified behavior. cc @rust-lang/lang

Summary for T-lang

This PR proposes to elevate #[optimize] attribute (as specified in RFC 2412) applied to unsupported HIR nodes from a warn-by-default unused_attributes lint to a hard error.

The RFC explains the rationale for emitting a warn-by-default unused_attributes lint as (emphasis mine with minor corrections)

#[optimize] attribute applied to non function-like items (such as struct) or non function-like expressions (i.e. not closures) is considered “unused” as of this RFC and should fire the unused_attributes lint (unless the same attribute was used for a function-like item or expression, via e.g. propagation). Some future RFC may assign some behaviour to this attribute with respect to such definitions.

Presumably, this was only designated as a warn-by-default unused_attribute lint to allow future extensions for the #[optimize] attribute for more HIR nodes?

In particular, the RFC and the tracking issue #54882 states an unresolved question (edited by me for correct lint name):

Are the propagation and unused_attributes approaches right?

Other attributes such as #[naked] reports a hard error if it is misapplied to HIR nodes that it does not intend to target.

Relevant context

@rustbot label +I-lang-nominated

@rustbot rustbot assigned jieyouxu and unassigned davidtwco Aug 11, 2024
@rustbot rustbot added the I-lang-nominated Nominated for discussion during a lang team meeting. label Aug 11, 2024
@jieyouxu jieyouxu added T-lang Relevant to the language team, which will review and decide on the PR/issue. S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 11, 2024
@Borgerr
Copy link
Contributor Author

Borgerr commented Aug 11, 2024

Forgot to remove the FIXME comment...

@Borgerr Borgerr force-pushed the misapplied-optimize-attribute branch from 093fe1f to 133e486 Compare August 11, 2024 15:12
@bors
Copy link
Contributor

bors commented Aug 29, 2024

☔ The latest upstream changes (presumably #129750) made this pull request unmergeable. Please resolve the merge conflicts.

@compiler-errors
Copy link
Member

compiler-errors commented Oct 16, 2024

Hi @Borgerr, I'd like to run a crater run to determine the fallout of this becoming a hard error. Could you rebase this PR, then we can kick that off?

@nikomatsakis
Copy link
Contributor

In general I prefer to give a hard error so that we can change the meaning rather than silently change behavior in the future, though sometimes practical considerations (i.e., widespread usage) make that not worth it. I doubt this attribute is heavily used however so I'm in favor of this change, assuming crater doesn't get too grouchy as a result.

@compiler-errors
Copy link
Member

Actually, no this doesn't need a crater run. Can you rebase this, though, so it can be approved? :D

@traviscross
Copy link
Contributor

@rustbot labels -I-lang-nominated

We discussed this today in triage, and our general feeling is that conservatively giving a hard error is our preference.

We talked about how, in defense of allowing these attributes liberally, that strictly speaking this is just an optimization, and so an unheeded attribute doesn't affect things in a language specification sense. But we still preferred to just give an error for now.

We note that this is still unstable. This is OK to go forward as far as lang is concerned.

@rustbot rustbot removed the I-lang-nominated Nominated for discussion during a lang team meeting. label Oct 16, 2024
@jieyouxu jieyouxu added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). labels Oct 16, 2024
@pnkfelix
Copy link
Member

I'll just jot a follow-up note here that one place where we probably do want to continue accepting #[optimize] is on async blocks, with the semantics that the attribute is applied to the poll method of the generated future.

(This is based on lang-team discussion here.)

@Borgerr Borgerr closed this Oct 17, 2024
@Borgerr Borgerr force-pushed the misapplied-optimize-attribute branch from 133e486 to dd51276 Compare October 17, 2024 04:41
@Borgerr
Copy link
Contributor Author

Borgerr commented Oct 17, 2024

@compiler-errors @nikomatsakis @pnkfelix
Incredibly silly and embarrassing that I accidentally closed this PR, however, my latest commits should reflect the desired changes. The PR can be reopened or I can open this elsewhere.

EDIT: FWIW, I have a different open PR (#131814) for this issue in case this helps speed things up. Thank you for your patience.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 20, 2024
…ute, r=jieyouxu

`optimize` attribute applied to things other than methods/functions/c…

…losures gives an error (rust-lang#128488)

Duplicate of rust-lang#128943, which I had accidentally closed when rebasing.

cc. `@jieyouxu` `@compiler-errors` `@nikomatsakis` `@traviscross` `@pnkfelix.`
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Oct 21, 2024
Rollup merge of rust-lang#131814 - Borgerr:misapplied-optimize-attribute, r=jieyouxu

`optimize` attribute applied to things other than methods/functions/c…

…losures gives an error (rust-lang#128488)

Duplicate of rust-lang#128943, which I had accidentally closed when rebasing.

cc. `@jieyouxu` `@compiler-errors` `@nikomatsakis` `@traviscross` `@pnkfelix.`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants