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 targets without unwinding in mir-opt, and improve --bless for it #112418

Merged
merged 13 commits into from
Jun 14, 2023

Conversation

pietroalbini
Copy link
Member

The main goal of this PR is to add support for targets without unwinding support in the mir-opt test suite, by adding the EMIT_MIR_FOR_EACH_PANIC_STRATEGY comment. Similarly to 32bit vs 64bit, when that comment is present, blessed output files will have the .panic-unwind or .panic-abort suffix, and the right one will be chosen depending on the target's panic strategy.

The EMIT_MIR_FOR_EACH_PANIC_STRATEGY comment replaced all the ignore-wasm32 comments in the mir-opt test suite, as those comments were added due to wasm32 being a target without unwinding support. The comment was also added on other tests that were only executed on x86 but were still panic strategy dependent.

The mir-opt suite was then blessed, which caused a ton of churn as most of the existing output files had to be renamed and (mostly) duplicated with the abort strategy.


After asking on Zulip, the main concern about this change is it'd make blessing the mir-opt suite even harder, as you'd need to both bless it with an unwinding target and an aborting target. This exacerbated the current situation, where you'd need to bless it with a 32bit and a 64bit target already.

Because of that, this PR also makes significant enhancements to --bless for the mir-opt suite, where it will automatically bless the suite four times with different targets, while requiring minimal cross-compilation.

To handle the 32bit vs 64bit blessing, there is now an hardcoded list of target mapping between 32bit and 64bit. The goal of the list is to find a related target that will probably work without requiring additional cross-compilation toolchains on the system. If a mapping is found, bootstrap will bless the suite with both targets, otherwise just with the current target.

To handle the panic strategy blessing (abort vs unwind), I had to resort to what I call "synthetic targets". For each of the target we're blessing (so either the current one, or a 32bit and a 64bit depending on the previous paragraph), bootstrap will extract the JSON spec of the target and change it to include "panic-strategy": "abort". It will then build the standard library with this synthetic target, and bless the mir-opt suite with it.

As a result of these changes, blessing the mir-opt suite will actually bless it two or four times with different targets, ensuring all possible variants are actually blessed.


This PR is best reviewed commit-by-commit.

r? @jyn514
cc @saethlin @oli-obk

@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-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jun 8, 2023
@pietroalbini
Copy link
Member Author

Most of the diff here is blessing.

@rust-log-analyzer

This comment has been minimized.

@saethlin
Copy link
Member

saethlin commented Jun 8, 2023

The EMIT_MIR_FOR_EACH_PANIC_STRATEGY comment replaced all the ignore-wasm32 comments in the mir-opt test suite

Is that the right default? Should we always emit MIR for each panic strategy? Or emit MIR for each panic strategy if they are different?

@pietroalbini
Copy link
Member Author

Is that the right default? Should we always emit MIR for each panic strategy? Or emit MIR for each panic strategy if they are different?

Note that I didn't add EMIT_MIR_FOR_EACH_PANIC_STRATEGY unconditionally, just in the (large) subset of tests that were ignored on wasm32 due to being broken due to aborting.

Should we always emit MIR for each panic strategy?

If that's the direction you all want to go with I'm ok with changing the implementation. Around half of the tests right now have EMIT_MIR_FOR_EACH_PANIC_STRATEGY, so it'd still be a pretty large increase in the number of output files.

Or emit MIR for each panic strategy if they are different?

This is a way more complex change than this PR unfortunately. This PR doesn't make any significant change to compiletest (other than using a suffix if the test is marked correctly), with all the unwind vs abort magic done by bootstrap invoking compiletest multiple times.

@saethlin
Copy link
Member

saethlin commented Jun 8, 2023

It sounds like my suggestion is a great candidate for a follow-up PR, perhaps by me. Thanks!

@jyn514
Copy link
Member

jyn514 commented Jun 8, 2023

i don't have time for reviews right now, please don't assign me.

r? @saethlin, but feel free to r? bootstrap if you're not comfortable reviewing

@rustbot rustbot assigned saethlin and unassigned jyn514 Jun 8, 2023
@saethlin
Copy link
Member

saethlin commented Jun 9, 2023

I've read over this and it looks mostly fine to me? In terms of improving the mir-opt test suite this is a good step forward, and it looks to me like an improvement in usability.

But the majority of this is changes to bootstrap, which I don't think I can really have an informed opinion on.

r? bootstrap

@rustbot rustbot assigned onur-ozkan and unassigned saethlin Jun 9, 2023
@onur-ozkan
Copy link
Member

I will do the review within the next couple of days.

@bors
Copy link
Contributor

bors commented Jun 11, 2023

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

Copy link
Member

@onur-ozkan onur-ozkan left a comment

Choose a reason for hiding this comment

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

Bootstrap changes looks good to me.

This will be needed to create synthetic targets in future commits.
Some targets are added to these hashmaps at runtime, and are not present
during dry runs. To avoid errors, this commit changes all the related
functions to always return empty strings/paths during dry runs.
It might happen that a synthetic target name does not match one of the
hardcoded ones in std's build script, causing std to fail to build. This
commit changes the std build script avoid including the restricted-std
feature unconditionally when a synthetic target is being built.
To reproduce the changes in this commit locally:

- Run `./x test tidy` and remove all the output files not associated
  with a test file anymore, as reported by tidy.
- Run `./x test tests/mir-opt --bless` to generate the new outputs.
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (afa9fef): comparison URL.

Overall result: ❌✅ regressions and improvements - ACTION NEEDED

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

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.3% [0.2%, 0.3%] 3
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.3% [-1.3%, -1.3%] 1
All ❌✅ (primary) 0.3% [0.2%, 0.3%] 3

Max RSS (memory usage)

Results

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)
1.5% [1.5%, 1.5%] 1
Regressions ❌
(secondary)
2.0% [1.8%, 2.2%] 2
Improvements ✅
(primary)
-0.2% [-0.2%, -0.2%] 1
Improvements ✅
(secondary)
-1.9% [-1.9%, -1.9%] 1
All ❌✅ (primary) 0.7% [-0.2%, 1.5%] 2

Cycles

Results

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)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.1% [-2.1%, -2.1%] 1
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 648.095s -> 648.221s (0.02%)

@rustbot rustbot added the perf-regression Performance regression. label Jun 14, 2023
@lqd
Copy link
Member

lqd commented Jun 14, 2023

This PR doesn't change the compiler, and the perf changes are the opposite of #112400 (comment) noise basically returning to steady state.

@rustbot label: +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Jun 14, 2023
@pietroalbini pietroalbini deleted the pa-mir-opt-panic branch June 15, 2023 08:22
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jun 18, 2023
Don't try to auto-bless 32-bit `mir-opt` tests on ARM Mac hosts

rust-lang#112418 added special support for automatically blessing 32-bit output on 64-bit hosts, for the subset of `mir-opt` tests that are pointer-width-dependent.

This relies on the 64-bit host having some corresponding 32-bit target that can be built “easily”. For most 64-bit hosts this is fine, but ARM Macs don't have a corresponding 32-bit target. (There have never been 32-bit ARM Macs, and ARM Macs don't have the libraries needed for building `i686-apple-darwin`.)

There is an entry for `("i686-apple-darwin", "aarch64-apple-darwin")` in the list of corresponding 32-bit platforms, but this doesn't actually work on ARM Macs. Instead, the bootstrap invocation fails to build the necessary 32-bit target support, and nothing gets tested or blessed.

According to [this Zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Can't.20bless.20any.20mir-opt.20tests.20on.20aarch64.20Mac/near/367109789), that mapping was only added because the author assumed it would work. But since it doesn't actually work on ARM Macs, the solution is to just remove that mapping.

With the mapping removed, ARM Macs still can't auto-bless 32-bit output (they will see a warning instead), but at least they can now bless the output of `mir-opt` tests that don't care about pointer width.
compiler-errors added a commit to compiler-errors/rust that referenced this pull request Jun 18, 2023
Don't try to auto-bless 32-bit `mir-opt` tests on ARM Mac hosts

rust-lang#112418 added special support for automatically blessing 32-bit output on 64-bit hosts, for the subset of `mir-opt` tests that are pointer-width-dependent.

This relies on the 64-bit host having some corresponding 32-bit target that can be built “easily”. For most 64-bit hosts this is fine, but ARM Macs don't have a corresponding 32-bit target. (There have never been 32-bit ARM Macs, and ARM Macs don't have the libraries needed for building `i686-apple-darwin`.)

There is an entry for `("i686-apple-darwin", "aarch64-apple-darwin")` in the list of corresponding 32-bit platforms, but this doesn't actually work on ARM Macs. Instead, the bootstrap invocation fails to build the necessary 32-bit target support, and nothing gets tested or blessed.

According to [this Zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Can't.20bless.20any.20mir-opt.20tests.20on.20aarch64.20Mac/near/367109789), that mapping was only added because the author assumed it would work. But since it doesn't actually work on ARM Macs, the solution is to just remove that mapping.

With the mapping removed, ARM Macs still can't auto-bless 32-bit output (they will see a warning instead), but at least they can now bless the output of `mir-opt` tests that don't care about pointer width.
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 30, 2023
…i-obk

Fix loading target specs in compiletest not working with custom targets

In rust-lang#112454 (comment) it was pointed out that the PR broke blessing mir-opt tests. Since rust-lang#112418, blessing mir-opt tests generates "synthetic targets", which are custom target specs. Those specs are not included in `--print=all-target-specs-json`, and rust-lang#112454 required that the current target was returned by that flag.

This PR fixes the breakage by loading the target spec for the current target explicitly, if a custom target is detected.

r? `@oli-obk`
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. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. 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-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants