-
Notifications
You must be signed in to change notification settings - Fork 13.4k
add asm_cfg
: #[cfg(...)]
within asm!
#140367
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
base: master
Are you sure you want to change the base?
Conversation
let is_configured_out = | ||
ecx.ecfg.features.asm_cfg() && strip_unconfigured.configure(attributes).is_none(); | ||
|
||
let template = p.parse_expr()?; |
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.
The fact that we use parse_expr
here mean that this does not work, and does not produce a great error message. This complains about an unexpected ,
after the 6
, but the real problem is that this cannot possibly be or expand to a string literal.
asm!(
#[cfg(false)]
a = const 6,
"nop",
);
Maybe we should specialize the parser to specifically only parse string literals and item macros?
if p.token == token::Eof { | ||
return Err(dcx.create_err(errors::AsmRequiresTemplate { span: sp })); | ||
} | ||
|
||
let first_template = p.parse_expr()?; | ||
let first_template = loop { | ||
let attributes = AsmAttrVec::parse(ecx, p)?; |
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.
attributes are now parsed before the parse_expr
below, and never attached to the expression. In theory that could interact with #[feature(stmt_expr_attributes)]
, but:
- that feature is unstable
- any attributes it parsed would have no effect
_ => { | ||
ecx.dcx().emit_err(errors::AsmAttributeNotSupported { span: attr.span() }); | ||
} |
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.
non-cfg
attributes are now accepted by the parser, but emit this error. Previously attributes were only parsed (and later rejected, unless #[feature(stmt_expr_attributes)]
was enabled) on expressions. We now also always parse them on operands.
This comment has been minimized.
This comment has been minimized.
Hmm, rust analyzer also parses the assembly, but from what I can see it has no way of evaluating the @rust-lang/rust-analyzer how can we make this work? |
(I haven't looked at the PR, but) parsing does not evaluated cfgs. Hir lowering does. |
Well in any case the parser doesn't. I'm not exactly sure where to draw the line for when HIR lowering starts, but certainly macro expansion of builtin macros is able to do it, e.g. here for rust/compiler/rustc_builtin_macros/src/cfg.rs Lines 24 to 30 in 267cae5
Anyway, are you saying that rust-analyzer just cannot evaluate cfg's while parsing the |
rust-analyzer has to duplicate these changes either way. We don't use any of the touched rustc crates here. |
Reminder, once the PR becomes ready for a review, use |
I'm still take a look through this, but I don't know enough about this area of the compiler to give a good review. Picking somebody who shows up in the blame a lot: r? @nnethercote |
Some changes occurred in src/tools/rustfmt cc @rust-lang/rustfmt |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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 author
☔ The latest upstream changes (presumably #141232) made this pull request unmergeable. Please resolve the merge conflicts. |
5f856d4
to
0e567bd
Compare
This comment has been minimized.
This comment has been minimized.
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.
At rustweek we discussed moving the asm parser to rustc_parse
. I've now made that change and think it's the right call here:
- we don't need to expose attribute parsing logic or hand-roll our own attribute parser
- rustfmt was able to drop the dependency on
rustc_builtin_macros
@rustbot ready
tests/ui/asm/cfg.rs
Outdated
} | ||
|
||
fn options() { | ||
// Without the cfg, this throws an error that the `noreturn` option is provided twice. |
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.
Comment is out of date? I don't see noreturn
in the code.
Looks good, r=me. One nit in a test comment. About the moving of the code to @bors delegate=folkertdev |
✌️ @folkertdev, you can now approve this pull request! If @nnethercote told you to " |
Ah, I see you wrote "we don't need to expose attribute parsing logic or hand-roll our own attribute parser" above. 👍 |
Thanks everyone! |
tracking issue: #140364
blocked on: #140490
This feature was discussed in #140279. It allows configuring templates and operands in the assembly macros, for example:
r? @tgross35
cc @traviscross @Amanieu
Now builds on #140490, which should be merged first.