-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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.
The job Click to see the possible cause of the failure (guessed by this bot)
|
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. |
tracking issue: #140364
This feature was discussed in #140279. It allows configuring templates and operands in the assembly macros, for example:
r? @tgross35
cc @traviscross @Amanieu
This needs some squashing, but I suspect we'll iterate a bunch here. I'll leave some inline comments too.