|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "Bisecting Rust Compiler Regressions with cargo-bisect-rustc" |
| 4 | +author: Santiago Pastorino |
| 5 | +team: the compiler team <https://www.rust-lang.org/governance/teams/compiler> |
| 6 | +--- |
| 7 | + |
| 8 | +Let's say that you've just updated the Rust compiler version and have |
| 9 | +tried to compile your application and see a failure that wasn't there |
| 10 | +before. That's likely due to a regression in the compiler. We've just |
| 11 | +released |
| 12 | +[`cargo-bisect-rustc`](https://github.com/rust-lang/cargo-bisect-rustc), |
| 13 | +a tool that makes it super easy to find exactly when the regression |
| 14 | +happened. |
| 15 | + |
| 16 | +`cargo-bisect-rustc` automatically downloads rustc artifacts and tests |
| 17 | +them against a project you provide until it finds the regression. At |
| 18 | +minimum, it will identify the nightly release which triggered the |
| 19 | +regression; but if the regression occurred in the last 168 days, it will |
| 20 | +even figure out the exact PR, which is often very useful in helping us |
| 21 | +fix the problem. |
| 22 | + |
| 23 | +`cargo-bisect-rustc` was created originally by Mark Rousskov. I extended |
| 24 | +it recently to make it easier to use. |
| 25 | + |
| 26 | +To install the tool run: |
| 27 | + |
| 28 | +```sh |
| 29 | +cargo install cargo-bisect-rustc |
| 30 | +``` |
| 31 | + |
| 32 | +## Finding a regression |
| 33 | + |
| 34 | +We are going to use [this "old" reported rustc |
| 35 | +regression](https://github.com/rust-lang/rust/issues/64945) as an |
| 36 | +example: |
| 37 | + |
| 38 | +Our application consists only of this file: |
| 39 | + |
| 40 | +```rust |
| 41 | +pub struct Slice<'a, T>(&'a [T]); |
| 42 | + |
| 43 | +impl<'a, T: 'a> Slice<'a, T> { |
| 44 | + pub const EMPTY: Self = Slice ({ |
| 45 | + let v: &[T] = &[]; |
| 46 | + v |
| 47 | + }); |
| 48 | +} |
| 49 | + |
| 50 | +fn main() { |
| 51 | + let s = Slice(&[1, 2]); |
| 52 | + assert!(s.0 != Slice::EMPTY.0); |
| 53 | +} |
| 54 | +``` |
| 55 | + |
| 56 | +Then we run `cargo bisect-rustc --end=2019-10-02`. |
| 57 | + |
| 58 | +Since this bug was fixed on 2019-10-03, we're using 2019-10-02 as the |
| 59 | +end We need to provide the end point for this particular example, given |
| 60 | +that this bug was fixed on 2019-10-03, we're using 2019-10-02 as the end |
| 61 | +point. If you don't provide an ending point it assumes that the end |
| 62 | +point is today's nightly or your currently installed nightly. If you |
| 63 | +don't provide a start point as we're doing it tries to find one by |
| 64 | +regressing in time. If you know if a failing starting point it would be |
| 65 | +faster if you just provide that one. |
| 66 | + |
| 67 | +By default it will run `cargo build` in the project and check whether or |
| 68 | +not it fails. After finding a nightly that has regressed it is going to |
| 69 | +automatically search for the commit that introduced the regression. |
| 70 | + |
| 71 | +Let's see the tool in action: |
| 72 | + |
| 73 | +The tool starts by downloading various nightly compilers, trying to find |
| 74 | +a date when the program worked ... |
| 75 | + |
| 76 | +``` |
| 77 | +checking nightly-2019-10-02 |
| 78 | +std for x86_64-unknown-linux-gnu: 172.87 MB / 172.87 MB [===============================================================================================================================================================] 100.00 % 10.67 MB/s uninstalling nightly-2019-10-02 |
| 79 | +checking nightly-2019-09-30 |
| 80 | +... |
| 81 | +``` |
| 82 | + |
| 83 | +Once it has one failing and working point it starts bisecting ... |
| 84 | +``` |
| 85 | +std for x86_64-unknown-linux-gnu: 173.43 MB / 173.43 MB [===============================================================================================================================================================] 100.00 % 12.82 MB/s uninstalling nightly-2019-09-29 |
| 86 | +tested nightly-2019-09-29, got No |
| 87 | +searched toolchains nightly-2019-09-28 through nightly-2019-09-30 |
| 88 | +regression in nightly-2019-09-30 |
| 89 | +``` |
| 90 | + |
| 91 | +Once it finds a nightly, it starts to search the PRs that went into that |
| 92 | +nightly build ... |
| 93 | +``` |
| 94 | +looking for regression commit between 2019-09-30 and 2019-09-29 |
| 95 | +fetching commits from 488381ce9ef0ceabe83b73127c659e5d38137df0 to 8431f261dd160021b6af85916f161a13dd101ca0 |
| 96 | +... |
| 97 | +searched toolchains 488381ce9ef0ceabe83b73127c659e5d38137df0 through 8431f261dd160021b6af85916f161a13dd101ca0 |
| 98 | +regression in 0bbab7d99dde8620604fb265706dc8bff20345a7 |
| 99 | +``` |
| 100 | + |
| 101 | +Finally, when it finds the PR that broke the compiler, it generates a |
| 102 | +bug report that you can copy and paste! |
| 103 | + |
| 104 | +```` |
| 105 | +================================================================================== |
| 106 | += Please open an issue on Rust's github repository = |
| 107 | += https://github.com/rust-lang/rust/issues/new = |
| 108 | += Below you will find a text that would serve as a starting point of your report = |
| 109 | +================================================================================== |
| 110 | +
|
| 111 | +# Regression found in the compiler |
| 112 | +
|
| 113 | +searched nightlies: from nightly-2019-09-28 to nightly-2019-09-30 |
| 114 | +regressed nightly: nightly-2019-09-30 |
| 115 | +searched commits: from https://github.com/rust-lang/rust/commit/488381ce9ef0ceabe83b73127c659e5d38137df0 to https://github.com/rust-lang/rust/commit/8431f261dd160021b6af85916f161a13dd101ca0 |
| 116 | +regressed commit: https://github.com/rust-lang/rust/commit/0bbab7d99dde8620604fb265706dc8bff20345a7 |
| 117 | +source code: URL OF A REPOSITORY THAT REPRODUCES THE ERROR |
| 118 | +
|
| 119 | +## Instructions |
| 120 | +
|
| 121 | +Please give the steps for how to build your repository (platform, system dependencies, etc.) |
| 122 | +## Error |
| 123 | +
|
| 124 | +<details><summary>COLLAPSIBLE ERROR STACKTRACE</summary> |
| 125 | +<p> |
| 126 | +
|
| 127 | +```bash |
| 128 | +Paste the error the compiler is giving |
| 129 | +``` |
| 130 | +
|
| 131 | +</p></details> |
| 132 | +```` |
| 133 | + |
| 134 | +This tells us that the regression started with |
| 135 | +[`0bbab7d99dde8620604fb265706dc8bff20345a7`](https://github.com/rust-lang/rust/commit/0bbab7d99dde8620604fb265706dc8bff20345a7) |
| 136 | +and you can look at the git log to find the PR. In this case is |
| 137 | +[#64470](https://github.com/rust-lang/rust/pull/64470). |
| 138 | + |
| 139 | +## Call for action: try the tool |
| 140 | + |
| 141 | +Please, give this tool a try and if you find yourself updating your |
| 142 | +application and it stops building, it's likely that you're hitting a |
| 143 | +regression. As you can see at the end of the execution of the tool, if a |
| 144 | +regression is found the tool gives you a report that you can paste on a |
| 145 | +github issue on the [Rust repo](https://github.com/rust-lang/rust). |
| 146 | + |
| 147 | +## Call for action: get involved in the development of cargo-bisect-rustc |
| 148 | + |
| 149 | +There are also a lot of things to improve in the tool and a lot of bugs |
| 150 | +to fix. There are a bunch of reported issues that are easy to fix, |
| 151 | +[check them |
| 152 | +out](https://github.com/rust-lang/cargo-bisect-rustc/issues). You can |
| 153 | +also, reach us out. You can find me and the rest of the compiler |
| 154 | +contributors and members in [Zulip's #t-compiler/cargo-bisect-rustc |
| 155 | +stream](https://rust-lang.zulipchat.com/#narrow/stream/217417-t-compiler.2Fcargo-bisect-rustc). |
| 156 | +Sign up there if you haven't already and do not hesitate to ask |
| 157 | +questions or even to send me a direct message if you don't know where to |
| 158 | +start. |
0 commit comments