-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Stabilize asm_cfg
#147736
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
Stabilize asm_cfg
#147736
Conversation
|
cc @tgross35 |
|
@rfcbot merge |
|
Team member @joshtriplett has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. |
|
@rfcbot reviewed |
|
I agree that the lint on positional arguments isn't a blocker, though I think it's highly desirable. |
I don't think this is a problem, since it's not likely that people will expect it to work. |
|
@folkertdev, does this just allow it for |
|
Macros are not currently expanded, e.g. emits I don't think we currently allow attributes on arguments to builtin macros. E.g. I'll look at what we can do here, but I suspect it'll be tricky. |
(Edit: When I had tested this, I was in a file where I had enabled
The relevant parts of the Reference are The latter two say:
What would be a bit less than elegant would be to have to say, "the |
So anything that these "attributes" can potentially do (eager expansion or something else) needs to be implemented manually by the |
This is really an implementation detail. Actually The We do actually parse arbitrary attributes on the assembly arguments, but anything besides |
Oops... when I tested this, I was in a file where I'd enabled |
|
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
The implementation of attributes for asm macro template strings and operands doesn't use the normal system in `rustc` for handling attributes. This leads to the limitations and may lead to subtle divergences in behavior. Let's make a note about this. For background, see: - rust-lang#2063 (comment) - rust-lang/rust#147736 (comment)
|
@rustbot labels -S-waiting-on-documentation The Reference PR has been approved; this is now good to go as far as lang-docs is concerned, and the lang FCP has completed, so this is good to go as far as lang is concerned. |
|
Will you perform the code review as well (the changes here are very straightforward), or should we assign someone else? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
@rustbot reroll |
|
@rustbot reroll |
|
@bors r+ rollup |
Rollup of 8 pull requests Successful merges: - #147736 (Stabilize `asm_cfg`) - #148652 (Cleanup and refactor FnCtxt::report_no_match_method_error) - #149167 (skip checking supertraits in object candidate for `NormalizesTo` goal) - #149210 (fix: Do not ICE on normalization failure of an extern static item) - #149268 (add implementation-internal namespace for globalasm) - #149274 (Fix invalid link generation for type alias methods) - #149302 (Fix comment wording in simplify_comparison_integral.rs) - #149305 (Simplify OnceCell Clone impl) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #147736 - folkertdev:stabilize-asm-cfg, r=jdonszelmann Stabilize `asm_cfg` tracking issue: #140364 closes #140364 Reference PR: - rust-lang/reference#2063 # Request for Stabilization ## Summary The `cfg_asm` feature allows `#[cfg(...)]` and `#[cfg_attr(...)]` on the arguments of the assembly macros, for instance: ```rust asm!( // or global_asm! or naked_asm! "nop", #[cfg(target_feature = "sse2")] "nop", // ... #[cfg(target_feature = "sse2")] a = const 123, // only used on sse2 ); ``` ## Semantics Templates, operands, `options` and `clobber_abi` in the assembly macros (`asm!`, `naked_asm!` and `global_asm!`) can be annotated with `#[cfg(...)]` and `#[cfg_attr(...)]`. When the condition evaluates to true, the annotated argument has no effect, and is completely ignored when expanding the assembly macro. ## Documentation reference PR: rust-lang/reference#2063 ## Tests - [tests/ui/asm/cfg.rs](https://github.com/rust-lang/rust/blob/master/tests/ui/asm/cfg.rs) checks that `cfg`'d arguments where the condition evaluates to false have no effect - [tests/ui/asm/cfg-parse-error.rs](https://github.com/rust-lang/rust/blob/master/tests/ui/asm/cfg.rs) checks the parsing rules (parsing effectively assumes that the cfg conditions are all true) ## History - #140279 - #140367 # Resolved questions **how are other attributes handled** Other attributes are parsed, but explicitly rejected. # unresolved questions **operand before template** The current implementation expects at least one template string before any operands. In the example below, if the `cfg` condition evaluates to true, the assembly block is ill-formed. But even when it evaluates to `false` this block is rejected, because the parser still expects just a template (a template is parsed as an expression and then validated to ensure that it is or expands to a string literal). Changing how this works is difficult. ```rust // This is rejected because `a = out(reg) x` does not parse as an expresion. asm!( #[cfg(false)] a = out(reg) x, //~ ERROR expected token: `,` "", ); ``` **lint on positional arguments?** Adding a lint to warn on the definition or use of positional arguments being `cfg`'d out was discussed in #140279 (comment) and subsequent comments. Such a lint is not currently implemented, but that may not be a blocker based on the comments there. r? `@traviscross` (I'm assuming you'll reassign as needed)
Rollup of 8 pull requests Successful merges: - rust-lang/rust#147736 (Stabilize `asm_cfg`) - rust-lang/rust#148652 (Cleanup and refactor FnCtxt::report_no_match_method_error) - rust-lang/rust#149167 (skip checking supertraits in object candidate for `NormalizesTo` goal) - rust-lang/rust#149210 (fix: Do not ICE on normalization failure of an extern static item) - rust-lang/rust#149268 (add implementation-internal namespace for globalasm) - rust-lang/rust#149274 (Fix invalid link generation for type alias methods) - rust-lang/rust#149302 (Fix comment wording in simplify_comparison_integral.rs) - rust-lang/rust#149305 (Simplify OnceCell Clone impl) r? `@ghost` `@rustbot` modify labels: rollup
tracking issue: #140364
closes #140364
Reference PR:
cfgconditions on inline assembly templates and operands reference#2063Request for Stabilization
Summary
The
cfg_asmfeature allows#[cfg(...)]and#[cfg_attr(...)]on the arguments of the assembly macros, for instance:Semantics
Templates, operands,
optionsandclobber_abiin the assembly macros (asm!,naked_asm!andglobal_asm!) can be annotated with#[cfg(...)]and#[cfg_attr(...)]. When the condition evaluates to true, the annotated argument has no effect, and is completely ignored when expanding the assembly macro.Documentation
reference PR: rust-lang/reference#2063
Tests
cfg'd arguments where the condition evaluates to false have no effectHistory
#[cfg(...)]withinasm!#140279asm_cfg:#[cfg(...)]withinasm!#140367Resolved questions
how are other attributes handled
Other attributes are parsed, but explicitly rejected.
unresolved questions
operand before template
The current implementation expects at least one template string before any operands. In the example below, if the
cfgcondition evaluates to true, the assembly block is ill-formed. But even when it evaluates tofalsethis block is rejected, because the parser still expects just a template (a template is parsed as an expression and then validated to ensure that it is or expands to a string literal).Changing how this works is difficult.
lint on positional arguments?
Adding a lint to warn on the definition or use of positional arguments being
cfg'd out was discussed in #140279 (comment) and subsequent comments. Such a lint is not currently implemented, but that may not be a blocker based on the comments there.r? @traviscross (I'm assuming you'll reassign as needed)