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

Use the same mir-opt bless targets on all platforms #120060

Merged
merged 4 commits into from
Feb 7, 2024

Conversation

saethlin
Copy link
Member

@saethlin saethlin commented Jan 17, 2024

This undoes some of the implementation in #119035, but not the effect. Sorry for the churn, I've learned a lot about how all this works over the past few weeks.

The objective here is to make x test mir-opt --bless use the same set of targets on all platforms. It didn't do that from the start because bootstrap assumes that a target linker is available, so the availability of cross-linkers is how we ended up with MIR_OPT_BLESS_TARGET_MAPPING and poor support for blessing mir-opt tests from Aarch64 MacOS. This PR corrects that.

So I've adjusted the bless targets for mir-opt tests, as well as tweaked some of the logic in bootstrap about linker configuration so that we don't try to access the cache of cc/linker configuration when doing the mir-opt builds.

While working on that I realized that if I swapped from the cargo rustc -p std strategy to cargo check on the sysroot, I could use the existing code for check builds to bypass some linker logic. Sweet.

But just doing that doesn't work, because then mir-opt tests complain that they can't find an rlib for any of the standard library crates. That happens because nearly all the mir-opt tests are attempting to build CrateType::Executable. We already have all the MIR required for mir-opt tests from the rmeta files, but since rustc think we're trying to build an executable it demands we have access to all the upstream monomorphizations that only exist in rlibs, not the meta files in a MIR-only sysroot.

So to fix that, I've swapped all the mir-opt tests be passed --crate-type=rlib. That works, but leaves us with a few broken mir-opt tests which I've blessed or fixed up; we also lose MIR for some functions so I added -Clink-dead-code to paper over that. The inlining changes are because changing the crate-type perturbs the hashes that are compared here to sometimes let us do inlining even in a possibly-recursive call:

if callee_def_id.is_local() {
// Avoid a cycle here by only using `instance_mir` only if we have
// a lower `DefPathHash` than the callee. This ensures that the callee will
// not inline us. This trick even works with incremental compilation,
// since `DefPathHash` is stable.
if self.tcx.def_path_hash(caller_def_id).local_hash()
< self.tcx.def_path_hash(callee_def_id).local_hash()
{
return Ok(());
}

@rustbot
Copy link
Collaborator

rustbot commented Jan 17, 2024

r? @clubby789

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added 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) labels Jan 17, 2024
@saethlin saethlin force-pushed the mir-opt-bless-targets branch 4 times, most recently from ade79c2 to 9099c94 Compare January 21, 2024 01:18
@rustbot rustbot added the A-testsuite Area: The testsuite used to check the correctness of rustc label Jan 21, 2024
@saethlin saethlin changed the title Use a better set of targets for blessing mir-opt tests Use the same mir-opt bless targets on all platforms Jan 21, 2024
@saethlin saethlin marked this pull request as ready for review January 21, 2024 18:51
@saethlin
Copy link
Member Author

cc @rust-lang/wg-mir-opt

src/bootstrap/src/core/build_steps/test.rs Outdated Show resolved Hide resolved
src/tools/compiletest/src/runtest.rs Outdated Show resolved Hide resolved
@wesleywiser
Copy link
Member

r? wesleywiser

@rustbot rustbot assigned wesleywiser and unassigned clubby789 Jan 30, 2024
@wesleywiser
Copy link
Member

This is awesome! Thanks for working on this @saethlin 👍

@bors r+

@bors
Copy link
Contributor

bors commented Jan 31, 2024

📌 Commit 815d312 has been approved by wesleywiser

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 Jan 31, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 3, 2024
…wesleywiser

Use the same mir-opt bless targets on all platforms

This undoes some of the implementation in rust-lang#119035, but not the effect. Sorry for the churn, I've learned a lot about how all this works over the past few weeks.

The objective here is to make `x test mir-opt --bless` use the same set of targets on all platforms. It didn't do that from the start because bootstrap assumes that a target linker is available, so the availability of cross-linkers is how we ended up with `MIR_OPT_BLESS_TARGET_MAPPING` and poor support for blessing mir-opt tests from Aarch64 MacOS. This PR corrects that.

So I've adjusted the bless targets for mir-opt tests, as well as tweaked some of the logic in bootstrap about linker configuration so that we don't try to access the cache of cc/linker configuration when doing the mir-opt builds.

While working on that I realized that if I swapped from the `cargo rustc -p std` strategy to `cargo check` on the sysroot, I could use the existing code for check builds to bypass some linker logic. Sweet.

But just doing that doesn't work, because then mir-opt tests complain that they can't find an rlib for any of the standard library crates. That happens because nearly all the mir-opt tests are attempting to build `CrateType::Executable`. We already have all the MIR required for mir-opt tests from the rmeta files, but since rustc think we're trying to build an executable it demands we have access to all the upstream monomorphizations that only exist in rlibs, not the meta files in a MIR-only sysroot.

So to fix that, I've swapped all the mir-opt tests be passed `--crate-type=rlib`. That works, but leaves us with a few broken mir-opt tests which I've blessed or fixed up; we also lose MIR for some functions so I added `-Clink-dead-code` to paper over that. The inlining changes are because changing the crate-type perturbs the hashes that are compared here to sometimes let us do inlining even in a possibly-recursive call: https://github.com/rust-lang/rust/blob/4cb17b4e78e0540e49d2da884cc621a6bf6f47fa/compiler/rustc_mir_transform/src/inline.rs#L332-L341
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 3, 2024
…wesleywiser

Use the same mir-opt bless targets on all platforms

This undoes some of the implementation in rust-lang#119035, but not the effect. Sorry for the churn, I've learned a lot about how all this works over the past few weeks.

The objective here is to make `x test mir-opt --bless` use the same set of targets on all platforms. It didn't do that from the start because bootstrap assumes that a target linker is available, so the availability of cross-linkers is how we ended up with `MIR_OPT_BLESS_TARGET_MAPPING` and poor support for blessing mir-opt tests from Aarch64 MacOS. This PR corrects that.

So I've adjusted the bless targets for mir-opt tests, as well as tweaked some of the logic in bootstrap about linker configuration so that we don't try to access the cache of cc/linker configuration when doing the mir-opt builds.

While working on that I realized that if I swapped from the `cargo rustc -p std` strategy to `cargo check` on the sysroot, I could use the existing code for check builds to bypass some linker logic. Sweet.

But just doing that doesn't work, because then mir-opt tests complain that they can't find an rlib for any of the standard library crates. That happens because nearly all the mir-opt tests are attempting to build `CrateType::Executable`. We already have all the MIR required for mir-opt tests from the rmeta files, but since rustc think we're trying to build an executable it demands we have access to all the upstream monomorphizations that only exist in rlibs, not the meta files in a MIR-only sysroot.

So to fix that, I've swapped all the mir-opt tests be passed `--crate-type=rlib`. That works, but leaves us with a few broken mir-opt tests which I've blessed or fixed up; we also lose MIR for some functions so I added `-Clink-dead-code` to paper over that. The inlining changes are because changing the crate-type perturbs the hashes that are compared here to sometimes let us do inlining even in a possibly-recursive call: https://github.com/rust-lang/rust/blob/4cb17b4e78e0540e49d2da884cc621a6bf6f47fa/compiler/rustc_mir_transform/src/inline.rs#L332-L341
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 5, 2024
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#116284 (make matching on NaN a hard error, and remove the rest of illegal_floating_point_literal_pattern)
 - rust-lang#120060 (Use the same mir-opt bless targets on all platforms)
 - rust-lang#120214 (match lowering: consistently lower bindings deepest-first)
 - rust-lang#120326 (Actually abort in -Zpanic-abort-tests)
 - rust-lang#120396 (Account for unbounded type param receiver in suggestions)
 - rust-lang#120435 (Suggest name value cfg when only value is used for check-cfg)

r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 5, 2024
…wesleywiser

Use the same mir-opt bless targets on all platforms

This undoes some of the implementation in rust-lang#119035, but not the effect. Sorry for the churn, I've learned a lot about how all this works over the past few weeks.

The objective here is to make `x test mir-opt --bless` use the same set of targets on all platforms. It didn't do that from the start because bootstrap assumes that a target linker is available, so the availability of cross-linkers is how we ended up with `MIR_OPT_BLESS_TARGET_MAPPING` and poor support for blessing mir-opt tests from Aarch64 MacOS. This PR corrects that.

So I've adjusted the bless targets for mir-opt tests, as well as tweaked some of the logic in bootstrap about linker configuration so that we don't try to access the cache of cc/linker configuration when doing the mir-opt builds.

While working on that I realized that if I swapped from the `cargo rustc -p std` strategy to `cargo check` on the sysroot, I could use the existing code for check builds to bypass some linker logic. Sweet.

But just doing that doesn't work, because then mir-opt tests complain that they can't find an rlib for any of the standard library crates. That happens because nearly all the mir-opt tests are attempting to build `CrateType::Executable`. We already have all the MIR required for mir-opt tests from the rmeta files, but since rustc think we're trying to build an executable it demands we have access to all the upstream monomorphizations that only exist in rlibs, not the meta files in a MIR-only sysroot.

So to fix that, I've swapped all the mir-opt tests be passed `--crate-type=rlib`. That works, but leaves us with a few broken mir-opt tests which I've blessed or fixed up; we also lose MIR for some functions so I added `-Clink-dead-code` to paper over that. The inlining changes are because changing the crate-type perturbs the hashes that are compared here to sometimes let us do inlining even in a possibly-recursive call: https://github.com/rust-lang/rust/blob/4cb17b4e78e0540e49d2da884cc621a6bf6f47fa/compiler/rustc_mir_transform/src/inline.rs#L332-L341
@Zalathar
Copy link
Contributor

Zalathar commented Feb 5, 2024

bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 5, 2024
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#113833 (`std::error::Error` -> Trait Implementations: lifetimes consistency improvement)
 - rust-lang#115386 (PartialEq, PartialOrd: update and synchronize handling of transitive chains)
 - rust-lang#116284 (make matching on NaN a hard error, and remove the rest of illegal_floating_point_literal_pattern)
 - rust-lang#118960 (Add LocalWaker and ContextBuilder types to core, and LocalWake trait to alloc.)
 - rust-lang#120060 (Use the same mir-opt bless targets on all platforms)
 - rust-lang#120214 (match lowering: consistently lower bindings deepest-first)
 - rust-lang#120384 (Use `<T, U>` for array/slice equality `impl`s)

r? `@ghost`
`@rustbot` modify labels: rollup
@saethlin
Copy link
Member Author

saethlin commented Feb 7, 2024

bors failed because a new test was added that assumed fn main would have MIR generated. An obscure form of merge conflict.

@saethlin
Copy link
Member Author

saethlin commented Feb 7, 2024

Because this type of change has already been approved:
@bors r=wesleywiser

@bors
Copy link
Contributor

bors commented Feb 7, 2024

📌 Commit 3c7a8b9 has been approved by wesleywiser

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 Feb 7, 2024
@bors
Copy link
Contributor

bors commented Feb 7, 2024

⌛ Testing commit 3c7a8b9 with merge 53061d3...

bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 7, 2024
…sleywiser

Use the same mir-opt bless targets on all platforms

This undoes some of the implementation in rust-lang#119035, but not the effect. Sorry for the churn, I've learned a lot about how all this works over the past few weeks.

The objective here is to make `x test mir-opt --bless` use the same set of targets on all platforms. It didn't do that from the start because bootstrap assumes that a target linker is available, so the availability of cross-linkers is how we ended up with `MIR_OPT_BLESS_TARGET_MAPPING` and poor support for blessing mir-opt tests from Aarch64 MacOS. This PR corrects that.

So I've adjusted the bless targets for mir-opt tests, as well as tweaked some of the logic in bootstrap about linker configuration so that we don't try to access the cache of cc/linker configuration when doing the mir-opt builds.

While working on that I realized that if I swapped from the `cargo rustc -p std` strategy to `cargo check` on the sysroot, I could use the existing code for check builds to bypass some linker logic. Sweet.

But just doing that doesn't work, because then mir-opt tests complain that they can't find an rlib for any of the standard library crates. That happens because nearly all the mir-opt tests are attempting to build `CrateType::Executable`. We already have all the MIR required for mir-opt tests from the rmeta files, but since rustc think we're trying to build an executable it demands we have access to all the upstream monomorphizations that only exist in rlibs, not the meta files in a MIR-only sysroot.

So to fix that, I've swapped all the mir-opt tests be passed `--crate-type=rlib`. That works, but leaves us with a few broken mir-opt tests which I've blessed or fixed up; we also lose MIR for some functions so I added `-Clink-dead-code` to paper over that. The inlining changes are because changing the crate-type perturbs the hashes that are compared here to sometimes let us do inlining even in a possibly-recursive call: https://github.com/rust-lang/rust/blob/4cb17b4e78e0540e49d2da884cc621a6bf6f47fa/compiler/rustc_mir_transform/src/inline.rs#L332-L341
@rust-log-analyzer
Copy link
Collaborator

The job armhf-gnu failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@bors
Copy link
Contributor

bors commented Feb 7, 2024

💔 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 Feb 7, 2024
@saethlin
Copy link
Member Author

saethlin commented Feb 7, 2024

2024-02-07T06:09:14.6844893Z thread 'main' panicked at src/tools/remote-test-client/src/main.rs:310:9:
2024-02-07T06:09:14.6845640Z client.read_exact(&mut header) failed with Connection reset by peer (os error 104)

#97669

@bors retry

@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 Feb 7, 2024
@bors
Copy link
Contributor

bors commented Feb 7, 2024

⌛ Testing commit 3c7a8b9 with merge d6c46a2...

@bors
Copy link
Contributor

bors commented Feb 7, 2024

☀️ Test successful - checks-actions
Approved by: wesleywiser
Pushing d6c46a2 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Feb 7, 2024
@bors bors merged commit d6c46a2 into rust-lang:master Feb 7, 2024
12 checks passed
@rustbot rustbot added this to the 1.78.0 milestone Feb 7, 2024
@saethlin saethlin deleted the mir-opt-bless-targets branch February 7, 2024 16:28
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (d6c46a2): 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
Improvements ✅
(secondary)
-2.0% [-2.0%, -2.0%] 1
All ❌✅ (primary) - - 0

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

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: 664.096s -> 662.763s (-0.20%)
Artifact size: 308.20 MiB -> 308.24 MiB (0.01%)

Comment on lines +1875 to +1883
if cmd != "check" {
self.configure_linker(
compiler,
target,
&mut cargo,
&mut rustflags,
&mut rustdocflags,
&mut hostflags,
);
Copy link
Member

Choose a reason for hiding this comment

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

May I know the motivation behind this if check? It is currently causing redundant recompilations between x anything-but-not-check and x check.

Copy link
Member Author

Choose a reason for hiding this comment

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

Instead of cmd != "check" which is overly broad, for now it would suffice for this to be "is not a mir-opt test".

The linker configuration prevents cross-compilation. At a minimum, it panics if cc detection for the target didn't succeed.

Copy link
Member

Choose a reason for hiding this comment

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

Instead of cmd != "check" which is overly broad, for now it would suffice for this to be "is not a mir-opt test".

This will still cause recompilations (this time with x test --bless). What are the side effects of running this unconditionally?

Copy link
Member Author

Choose a reason for hiding this comment

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

If this is run unconditionally, bootstrap will panic when blessing mir-opt tests because the linker configuration innards assumes that we've done cc detection for the target. The panics look like this:

thread 'main' panicked at src/lib.rs:1195:25:
no entry found for key
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Build completed unsuccessfully in 0:04:05

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)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants