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

Add support for specifying multiple clobber_abi in asm! #89316

Merged
merged 4 commits into from
Nov 12, 2021

Conversation

asquared31415
Copy link
Contributor

r? @Amanieu
cc #72016
@rustbot label: +A-inline-assembly +F-asm

@rustbot rustbot added A-inline-assembly Area: inline asm!(..) F-asm `#![feature(asm)]` (not `llvm_asm`) labels Sep 28, 2021
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 28, 2021
@asquared31415
Copy link
Contributor Author

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?

@@ -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);
Copy link
Member

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();
Copy link
Member

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.

compiler/rustc_ast_lowering/src/asm.rs Outdated Show resolved Hide resolved
@@ -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")
Copy link
Member

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!`");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@Amanieu
Copy link
Member

Amanieu commented Sep 29, 2021

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 clobber_abi can be specified multiple times.

@Amanieu
Copy link
Member

Amanieu commented Sep 30, 2021

@bors r+

@bors
Copy link
Contributor

bors commented Sep 30, 2021

📌 Commit b159d95 has been approved by Amanieu

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 30, 2021
fee1-dead added a commit to fee1-dead-contrib/rust that referenced this pull request Oct 1, 2021
… r=Amanieu

Add support for specifying multiple clobber_abi in `asm!`

r? `@Amanieu`
cc rust-lang#72016
`@rustbot` label: +A-inline-assembly +F-asm
@fee1-dead
Copy link
Member

@bors r-

Failed in #89420 (comment)

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 1, 2021
Copy link
Contributor

@nbdd0121 nbdd0121 left a 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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if args.clobber_abis.len() > 0 {
if !args.clobber_abis.is_empty() {

@Amanieu
Copy link
Member

Amanieu commented Oct 7, 2021

Hmm actually I slightly prefer clobber_abi("A", "B").

@asquared31415
Copy link
Contributor Author

I like that syntax better too

Comment on lines 51 to 80
let mut abis = format!("`{}`", supported_abis[0]);
for m in &supported_abis[1..] {
let _ = write!(abis, ", `{}`", m);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let mut abis = format!("`{}`", supported_abis[0]);
for m in &supported_abis[1..] {
let _ = write!(abis, ", `{}`", m);
}
let abis = supported_abis.join(",");

Copy link
Contributor Author

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();
Copy link
Contributor

@nbdd0121 nbdd0121 Oct 8, 2021

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));
Copy link
Contributor

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_abis?

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
Copy link
Contributor

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".

@rust-log-analyzer

This comment has been minimized.

@Amanieu
Copy link
Member

Amanieu commented Oct 10, 2021

@bors r+

@bors
Copy link
Contributor

bors commented Oct 10, 2021

📌 Commit 111423454809b548c7d8ad195d100046d99dcd98 has been approved by Amanieu

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 10, 2021
@bors
Copy link
Contributor

bors commented Oct 10, 2021

⌛ Testing commit 111423454809b548c7d8ad195d100046d99dcd98 with merge f1b081eb34e3a1756703a5cd7884ae8132eb52ef...

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 10, 2021
@rust-log-analyzer

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
@Amanieu
Copy link
Member

Amanieu commented Nov 10, 2021

@bors r+

@bors
Copy link
Contributor

bors commented Nov 10, 2021

📌 Commit 3e799e4 has been approved by Amanieu

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 10, 2021
@bors
Copy link
Contributor

bors commented Nov 10, 2021

⌛ Testing commit 3e799e4 with merge 4de694226be8edf717148c78451fac31fb9ff4f5...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Nov 10, 2021

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 10, 2021
@Amanieu
Copy link
Member

Amanieu commented Nov 12, 2021

@bors r+

@bors
Copy link
Contributor

bors commented Nov 12, 2021

📌 Commit e80f300 has been approved by Amanieu

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 12, 2021
@bors
Copy link
Contributor

bors commented Nov 12, 2021

⌛ Testing commit e80f300 with merge 220ed09...

@bors
Copy link
Contributor

bors commented Nov 12, 2021

☀️ Test successful - checks-actions
Approved by: Amanieu
Pushing 220ed09 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Nov 12, 2021
@bors bors merged commit 220ed09 into rust-lang:master Nov 12, 2021
@rustbot rustbot added this to the 1.58.0 milestone Nov 12, 2021
@rust-timer
Copy link
Collaborator

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

@asquared31415 asquared31415 deleted the multiple-clobber-abi branch November 18, 2021 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inline-assembly Area: inline asm!(..) F-asm `#![feature(asm)]` (not `llvm_asm`) merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.