Skip to content

bootstrap: Fix stack printing when a step cycle is detected #138216

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Mar 9, 2025

Conversation

Zalathar
Copy link
Contributor

@Zalathar Zalathar commented Mar 8, 2025

When bootstrap detects a step dependency cycle (which represents a bootstrap bug), it is supposed to print out the contents of the step stack as part of its panic message.

However, while investigating #138205 it was found that bootstrap was actually printing out several copies of Any { .. }, because that is the Debug implementation for dyn Any. This is sadly not very helpful.

This PR fixes that problem by introducing a trait AnyDebug: Any + Debug that delegates to the underlying type's Debug implementation, while still allowing downcasting via Any.


The fixed behaviour can be verified manually (and is tested automatically) via a new dummy command, ./x run cyclic-step:

$ x run cyclic-step
Building bootstrap
    Finished `dev` profile [unoptimized] target(s) in 0.02s

thread 'main' panicked at src/bootstrap/src/core/builder/mod.rs:1521:17:


Cycle in build detected when adding CyclicStep { n: 0 }
	CyclicStep { n: 0 }
	CyclicStep { n: 1 }
	CyclicStep { n: 2 }

note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Build completed unsuccessfully in 0:00:00

@Zalathar Zalathar added the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label Mar 8, 2025
@rustbot
Copy link
Collaborator

rustbot commented Mar 8, 2025

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
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 the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 8, 2025
@Zalathar
Copy link
Contributor Author

Zalathar commented Mar 8, 2025

r? jieyouxu (or bootstrap)

@rustbot rustbot assigned jieyouxu and unassigned Mark-Simulacrum Mar 8, 2025
@jieyouxu
Copy link
Member

jieyouxu commented Mar 8, 2025

r? onur-ozkan (since you're looking at it already)

@onur-ozkan
Copy link
Member

Thanks!

@bors r+

@bors
Copy link
Collaborator

bors commented Mar 8, 2025

📌 Commit f83af2a has been approved by onur-ozkan

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 Mar 8, 2025
jieyouxu added a commit to jieyouxu/rust that referenced this pull request Mar 9, 2025
bootstrap: Fix stack printing when a step cycle is detected

When bootstrap detects a step dependency cycle (which represents a bootstrap bug), it is supposed to print out the contents of the step stack as part of its panic message.

However, while investigating rust-lang#138205 it was found that bootstrap was actually printing out several copies of `Any { .. }`, because that is the Debug implementation for `dyn Any`. This is sadly not very helpful.

This PR fixes that problem by introducing a `trait AnyDebug: Any + Debug` that delegates to the underlying type's Debug implementation, while still allowing downcasting via Any.

---

The fixed behaviour can be verified manually (and is tested automatically) via a new dummy command, `./x run cyclic-step`:

```
$ x run cyclic-step
Building bootstrap
    Finished `dev` profile [unoptimized] target(s) in 0.02s

thread 'main' panicked at src/bootstrap/src/core/builder/mod.rs:1521:17:

Cycle in build detected when adding CyclicStep { n: 0 }
	CyclicStep { n: 0 }
	CyclicStep { n: 1 }
	CyclicStep { n: 2 }

note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Build completed unsuccessfully in 0:00:00
```
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 9, 2025
Rollup of 16 pull requests

Successful merges:

 - rust-lang#122790 (Apply dllimport in ThinLTO)
 - rust-lang#136127 (Allow `*const W<dyn A> -> *const dyn A` ptr cast)
 - rust-lang#136968 (Turn order dependent trait objects future incompat warning into a hard error)
 - rust-lang#137147 (Add exclude to config.toml)
 - rust-lang#137319 (Stabilize `const_vec_string_slice`)
 - rust-lang#137885 (tidy: add triagebot checks)
 - rust-lang#138040 (compiler: Use `size_of` from the prelude instead of imported)
 - rust-lang#138052 (strip `-Wlinker-messages` wrappers from `rust-lld` rmake test)
 - rust-lang#138084 (Use workspace lints for crates in `compiler/`)
 - rust-lang#138158 (Move more layouting logic to `rustc_abi`)
 - rust-lang#138160 (depend more on attr_data_structures and move find_attr! there)
 - rust-lang#138192 (crashes: couple more tests)
 - rust-lang#138216 (bootstrap: Fix stack printing when a step cycle is detected)
 - rust-lang#138232 (Reduce verbosity of GCC build log)
 - rust-lang#138233 (Windows: Don't link std (and run-make) against advapi32, except on win7)
 - rust-lang#138242 (Revert "Don't test new error messages with the stage 0 compiler")

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 9, 2025
…iaskrgr

Rollup of 12 pull requests

Successful merges:

 - rust-lang#136127 (Allow `*const W<dyn A> -> *const dyn A` ptr cast)
 - rust-lang#136968 (Turn order dependent trait objects future incompat warning into a hard error)
 - rust-lang#137319 (Stabilize `const_vec_string_slice`)
 - rust-lang#137885 (tidy: add triagebot checks)
 - rust-lang#138040 (compiler: Use `size_of` from the prelude instead of imported)
 - rust-lang#138084 (Use workspace lints for crates in `compiler/`)
 - rust-lang#138158 (Move more layouting logic to `rustc_abi`)
 - rust-lang#138160 (depend more on attr_data_structures and move find_attr! there)
 - rust-lang#138192 (crashes: couple more tests)
 - rust-lang#138216 (bootstrap: Fix stack printing when a step cycle is detected)
 - rust-lang#138232 (Reduce verbosity of GCC build log)
 - rust-lang#138242 (Revert "Don't test new error messages with the stage 0 compiler")

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 92fd45b into rust-lang:master Mar 9, 2025
6 checks passed
@rustbot rustbot added this to the 1.87.0 milestone Mar 9, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Mar 9, 2025
Rollup merge of rust-lang#138216 - Zalathar:any-debug, r=onur-ozkan

bootstrap: Fix stack printing when a step cycle is detected

When bootstrap detects a step dependency cycle (which represents a bootstrap bug), it is supposed to print out the contents of the step stack as part of its panic message.

However, while investigating rust-lang#138205 it was found that bootstrap was actually printing out several copies of `Any { .. }`, because that is the Debug implementation for `dyn Any`. This is sadly not very helpful.

This PR fixes that problem by introducing a `trait AnyDebug: Any + Debug` that delegates to the underlying type's Debug implementation, while still allowing downcasting via Any.

---

The fixed behaviour can be verified manually (and is tested automatically) via a new dummy command, `./x run cyclic-step`:

```
$ x run cyclic-step
Building bootstrap
    Finished `dev` profile [unoptimized] target(s) in 0.02s

thread 'main' panicked at src/bootstrap/src/core/builder/mod.rs:1521:17:

Cycle in build detected when adding CyclicStep { n: 0 }
	CyclicStep { n: 0 }
	CyclicStep { n: 1 }
	CyclicStep { n: 2 }

note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Build completed unsuccessfully in 0:00:00
```
@Zalathar Zalathar deleted the any-debug branch March 10, 2025 00:28
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
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.

6 participants