-
Notifications
You must be signed in to change notification settings - Fork 13k
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 support for specifying multiple clobber_abi in asm!
#89316
Conversation
One concern I have is the increase of the size of ast::ItemKind, if that is a problem I think that it can be fixed with some boxed slices? |
77726da
to
db8af3f
Compare
compiler/rustc_ast/src/ast.rs
Outdated
@@ -2744,7 +2744,7 @@ pub enum ItemKind { | |||
} | |||
|
|||
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] | |||
rustc_data_structures::static_assert_size!(ItemKind, 112); |
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.
Consider boxing the InlineAsm
to avoid increasing the size of ItemKind
.
@@ -27,11 +28,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { | |||
.emit(); | |||
} | |||
|
|||
let mut clobber_abi = None; | |||
let mut clobber_abis = FxHashSet::default(); |
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.
Use a HashMap
keyed on the ABI, otherwise 2 identical ABIs with different spans will both be included.
@@ -210,7 +210,7 @@ fn parse_args<'a>( | |||
.span_labels(args.options_spans.clone(), "previous options") | |||
.span_label(span, "argument") | |||
.emit(); | |||
} else if let Some((_, abi_span)) = args.clobber_abi { | |||
} else if let Some(&(_, abi_span)) = args.clobber_abis.last() { | |||
ecx.struct_span_err(span, "arguments are not allowed after clobber_abi") | |||
.span_label(abi_span, "clobber_abi") |
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.
I'd like this to point to all the clobber_abi
spans, not just the last one.
@@ -322,7 +322,7 @@ fn parse_args<'a>( | |||
// Bail out now since this is likely to confuse MIR | |||
return Err(err); | |||
} | |||
if let Some((_, abi_span)) = args.clobber_abi { | |||
if let Some(&(_, abi_span)) = args.clobber_abis.last() { | |||
if is_global_asm { | |||
let err = | |||
ecx.struct_span_err(abi_span, "`clobber_abi` cannot be used with `global_asm!`"); |
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.
Same here.
Can you add this to grammar in the asm documentation in the unstable book? Also in the reference-level explanation add a note saying that |
@bors r+ |
📌 Commit b159d95 has been approved by |
… r=Amanieu Add support for specifying multiple clobber_abi in `asm!` r? `@Amanieu` cc rust-lang#72016 `@rustbot` label: +A-inline-assembly +F-asm
@bors r- Failed in #89420 (comment) |
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.
I wonder if the syntax should be
clobber_abi("A"), clobber_abi("B")
or
clobber_abi("A", "B")
@@ -322,10 +322,12 @@ fn parse_args<'a>( | |||
// Bail out now since this is likely to confuse MIR | |||
return Err(err); | |||
} | |||
if let Some((_, abi_span)) = args.clobber_abi { | |||
if args.clobber_abis.len() > 0 { |
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.
if args.clobber_abis.len() > 0 { | |
if !args.clobber_abis.is_empty() { |
Hmm actually I slightly prefer |
I like that syntax better too |
59bae7f
to
887caeb
Compare
let mut abis = format!("`{}`", supported_abis[0]); | ||
for m in &supported_abis[1..] { | ||
let _ = write!(abis, ", `{}`", m); | ||
} |
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.
let mut abis = format!("`{}`", supported_abis[0]); | |
for m in &supported_abis[1..] { | |
let _ = write!(abis, ", `{}`", m); | |
} | |
let abis = supported_abis.join(","); |
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 code there adds ` around the abi name, which can't be replicated using just join
like that.
@@ -27,31 +28,36 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { | |||
.emit(); | |||
} | |||
|
|||
let mut clobber_abi = None; | |||
let mut clobber_abis = FxHashMap::default(); |
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.
I think this shall be a Vec
. If there are multiple occurrence of the same ABI then it should be error (and emitted during macro expansion), not silently merged.
args.push(AsmArg::ClobberAbi(abi)); | ||
if let Some((_, abis)) = &asm.clobber_abis { | ||
for (abi, _) in abis { | ||
args.push(AsmArg::ClobberAbi(*abi)); |
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.
Wouldn't this still geenrate multiple clobber_abi
s?
new_abis.push((str_lit.symbol_unescaped, str_lit.span)); | ||
} | ||
Err(opt_lit) => { | ||
// A closing paren is only allowed after a comma, so make sure we've seen an abi before, or else there's a missing abi argument |
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.
I think it's best to treat non-string-literal case and no ABI specified case separately (given that this is now a comma delimited list), so if the user writes clobber_abi()
then we should say "at least an ABI name should be specified in clobber_abi
" rather than just "expected string literal".
This comment has been minimized.
This comment has been minimized.
5625ff6
to
1114234
Compare
@bors r+ |
📌 Commit 111423454809b548c7d8ad195d100046d99dcd98 has been approved by |
⌛ Testing commit 111423454809b548c7d8ad195d100046d99dcd98 with merge f1b081eb34e3a1756703a5cd7884ae8132eb52ef... |
This comment has been minimized.
This comment has been minimized.
Allow multiple clobber_abi in asm Update docs Fix aarch64 test Combine abis Emit duplicate ABI error, empty ABI list error multiple clobber_abi
c77cd0a
to
3e799e4
Compare
@bors r+ |
📌 Commit 3e799e4 has been approved by |
⌛ Testing commit 3e799e4 with merge 4de694226be8edf717148c78451fac31fb9ff4f5... |
This comment has been minimized.
This comment has been minimized.
💔 Test failed - checks-actions |
@bors r+ |
📌 Commit e80f300 has been approved by |
☀️ Test successful - checks-actions |
Finished benchmarking commit (220ed09): comparison url. Summary: This benchmark run did not return any relevant changes. If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. @rustbot label: -perf-regression |
r? @Amanieu
cc #72016
@rustbot label: +A-inline-assembly +F-asm