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

Move ZST ABI handling to rustc_target #125854

Merged
merged 1 commit into from
Aug 19, 2024
Merged

Conversation

beetrees
Copy link
Contributor

@beetrees beetrees commented Jun 1, 2024

Currently, target specific handling of ZST function call ABI (specifically passing them indirectly instead of ignoring them) is handled in rustc_ty_utils, whereas all other target specific function call ABI handling is located in rustc_target. This PR moves the ZST handling to rustc_target so that all the target-specific function call ABI handling is in one place. In the process of doing so, this PR fixes #125850 by ensuring that ZST arguments are always correctly ignored in the x86-64 "sysv64" ABI; any code which would be affected by this fix would have ICEd before this PR. Tests are also added using #[rustc_abi(debug)] to ensure this behaviour does not regress.

Fixes #125850

@rustbot
Copy link
Collaborator

rustbot commented Jun 1, 2024

r? @estebank

rustbot has assigned @estebank.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 1, 2024
@rustbot
Copy link
Collaborator

rustbot commented Jun 1, 2024

Some changes occurred in src/tools/compiletest

cc @jieyouxu

@bors
Copy link
Contributor

bors commented Jun 23, 2024

☔ The latest upstream changes (presumably #124733) made this pull request unmergeable. Please resolve the merge conflicts.

@estebank
Copy link
Contributor

r=me after rebase

@estebank estebank added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 12, 2024
@beetrees
Copy link
Contributor Author

beetrees commented Jul 12, 2024

@estebank Rebased. I've also added a normalize-stderr-test to the tests (taken from tests/ui/abi/debug.rs) to prevent the tests being sensitive to preferred alignment differences between targets.

@rustbot label -S-waiting-on-author

@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 12, 2024
@bors
Copy link
Contributor

bors commented Jul 31, 2024

☔ The latest upstream changes (presumably #128435) made this pull request unmergeable. Please resolve the merge conflicts.

@beetrees
Copy link
Contributor Author

beetrees commented Aug 2, 2024

I've rebased to fix the merge conflict.

@beetrees
Copy link
Contributor Author

Friendly ping @estebank: I think this can be r+'d now that I've rebased it (I don't have r+ permissions myself).

@Dylan-DPC
Copy link
Member

@bors r=estebank

@bors
Copy link
Contributor

bors commented Aug 18, 2024

📌 Commit b1493ba has been approved by estebank

It is now in the queue for this repository.

@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 Aug 18, 2024
@@ -652,6 +652,11 @@ impl<'a, Ty> ArgAbi<'a, Ty> {
}
}

/// Same as make_indirect, but doesn't check the current `PassMode`.
Copy link
Member

Choose a reason for hiding this comment

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

Would be good to give some kind of guidance when it is okay to use this. Presumably make_indirect has these checks for a reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since this is only needed for making ignored ZSTs indirect (a specific niche use-case), I've made the method more specific. Since this PR has already merged, I've submitted the changes as #129339.

// sparc64-unknown-linux-{gnu,musl,uclibc} doesn't ignore ZSTs.
if cx.target_spec().os == "linux"
&& matches!(&*cx.target_spec().env, "gnu" | "musl" | "uclibc")
&& arg.layout.is_zst()
Copy link
Member

Choose a reason for hiding this comment

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

This treats all ZST the same, no matter their alignment. So for instance [u32; 0] is also a ZST, but it has alignment 4. To only catch types like (), we have is_1zst.

Is catching even aligned ZST the right thing here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Clang/GCC pass ZSTs indirectly on these targets regardless of alignment.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 18, 2024
Move ZST ABI handling to `rustc_target`

Currently, target specific handling of ZST function call ABI (specifically passing them indirectly instead of ignoring them) is handled in `rustc_ty_utils`, whereas all other target specific function call ABI handling is located in `rustc_target`. This PR moves the ZST handling to `rustc_target` so that all the target-specific function call ABI handling is in one place. In the process of doing so, this PR fixes rust-lang#125850 by ensuring that ZST arguments are always correctly ignored in the x86-64 `"sysv64"` ABI; any code which would be affected by this fix would have ICEd before this PR. Tests are also added using `#[rustc_abi(debug)]` to ensure this behaviour does not regress.

Fixes rust-lang#125850
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 18, 2024
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#125854 (Move ZST ABI handling to `rustc_target`)
 - rust-lang#127623 (fix: fs::remove_dir_all: treat internal ENOENT as success)
 - rust-lang#128084 (Suggest adding Result return type for associated method in E0277.)
 - rust-lang#128902 (doc: std::env::var: Returns None for names with '=' or NUL byte)
 - rust-lang#129187 (bootstrap: fix clean's remove_dir_all implementation)
 - rust-lang#129235 (Check that `#[may_dangle]` is properly applied)
 - rust-lang#129245 (Typo)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors
Copy link
Contributor

bors commented Aug 18, 2024

⌛ Testing commit b1493ba with merge d0293c6...

@bors
Copy link
Contributor

bors commented Aug 19, 2024

☀️ Test successful - checks-actions
Approved by: estebank
Pushing d0293c6 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 19, 2024
@bors bors merged commit d0293c6 into rust-lang:master Aug 19, 2024
7 checks passed
@rustbot rustbot added this to the 1.82.0 milestone Aug 19, 2024
@bors bors mentioned this pull request Aug 19, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (d0293c6): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.2% [-0.2%, -0.2%] 1
Improvements ✅
(secondary)
-0.2% [-0.2%, -0.2%] 1
All ❌✅ (primary) -0.2% [-0.2%, -0.2%] 1

Max RSS (memory usage)

Results (secondary 1.2%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
3.9% [3.7%, 4.1%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-4.3% [-4.3%, -4.3%] 1
All ❌✅ (primary) - - 0

Cycles

Results (secondary 1.9%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
1.9% [1.6%, 2.2%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 751.033s -> 751.219s (0.02%)
Artifact size: 339.18 MiB -> 339.13 MiB (-0.01%)

@beetrees beetrees deleted the zst-arg-abi branch August 21, 2024 01:57
tgross35 added a commit to tgross35/rust that referenced this pull request Aug 21, 2024
…, r=RalfJung

Make `ArgAbi::make_indirect_force` more specific

As the method is only needed for making ignored ZSTs indirect on some ABIs, rename and add a doc-comment and `self.mode` check to make it harder to accidentally misuse. Addresses review feedback from rust-lang#125854 (comment).

r? `@RalfJung`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 21, 2024
…, r=RalfJung

Make `ArgAbi::make_indirect_force` more specific

As the method is only needed for making ignored ZSTs indirect on some ABIs, rename and add a doc-comment and `self.mode` check to make it harder to accidentally misuse. Addresses review feedback from rust-lang#125854 (comment).

r? ``@RalfJung``
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Aug 21, 2024
Rollup merge of rust-lang#129339 - beetrees:make-indirect-from-ignore, r=RalfJung

Make `ArgAbi::make_indirect_force` more specific

As the method is only needed for making ignored ZSTs indirect on some ABIs, rename and add a doc-comment and `self.mode` check to make it harder to accidentally misuse. Addresses review feedback from rust-lang#125854 (comment).

r? ``@RalfJung``
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-testsuite Area: The testsuite used to check the correctness of rustc 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-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) 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.

ICE when compiling for x86_64-pc-windows-gnu when passing a ZST using the "sysv64" ABI
7 participants