Skip to content

Cycle error from pretty printer with RUST_LOG #59985

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

Open
davidtwco opened this issue Apr 15, 2019 · 4 comments
Open

Cycle error from pretty printer with RUST_LOG #59985

davidtwco opened this issue Apr 15, 2019 · 4 comments
Labels
A-pretty Area: Pretty printing (including `-Z unpretty`) C-bug Category: This is a bug. I-cycle Issue: A query cycle occurred while none was expected T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@davidtwco
Copy link
Member

davidtwco commented Apr 15, 2019

(I wasn't able to find any existing discussion, issues or PRs about this, I'd not be surprised if someone had found it already, so my bad if this isn't a new problem)

Yesterday, I was about to take a look into #59494 (the test case for that will trigger this), running that test case with RUST_LOG=rustc::traits makes a cycle error happen instead of the expected ICE. I can get the ICE with just RUST_LOG=rustc::traits::select (IIRC), but not when I include other modules.

The cycle error comes from the pretty printer, in particular this line. I managed to resolve the issue, here's the diff that fixed it - when the pretty printer calls predicates_of for existential types then it ends up calling code with debug logs that print the same type, causing a cycle.

The diff above only bypasses the cycle error when RUST_LOG=rustc::ty::subst,rustc::ty::context,rustc_typeck, I assume it won't when you add more modules. Here's the relevant Zulip topic.

@davidtwco davidtwco added A-pretty Area: Pretty printing (including `-Z unpretty`) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 15, 2019
@davidtwco
Copy link
Member Author

This can be worked around using -Z verbose (relevant Discord chat).

@eddyb
Copy link
Member

eddyb commented Apr 18, 2019

cc @nikomatsakis @arielb1 How was this dealt with previously? For debug printing that happens to result in cycles with certain values of RUST_LOG?

@nikomatsakis
Copy link
Contributor

This is a thorny problem. We've never had a good solution.

In general, I think it's a problem that {:?} and {} share as much code as they do. I tend to think that {:?} should really be much more conservative and closer to the internal representation than it is, which might help us avoid some of these problems. (I basically only use the compiler with -Zverbose , for example, which tends to force it to include more information.) But this is really the sort of topic that's going to take some exploration.

(In fact, I don't particularly like that we implement {:?} at all, since I think we should be threading down contextual information -- and I think that information should be more than the tcx, which can use TLS, but should include e.g. the infcx or other such things. I liked the idea of the DebugWith trait we were using in Lark (along with a custom derive), which let us thread down different kinds of context and get different kinds of output as a result -- e.g., including the infcx would "resolve" inference variables -- but I never used it deeply enough to know if it was ultimately kind of annoying.)

@eddyb
Copy link
Member

eddyb commented May 1, 2019

We used to require methods for printing and it was really cumbersome.
IMO the best solution would be implicit scoped contexts that type-checked and passed as regular arguments (but behind the scenes, so the user doesn't have to mention them at every callsite).
But that's a language feature, and a pretty big one for Rust.

cc @eternaleye (who introduced me to this idea)

@fmease fmease added the I-cycle Issue: A query cycle occurred while none was expected label Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-pretty Area: Pretty printing (including `-Z unpretty`) C-bug Category: This is a bug. I-cycle Issue: A query cycle occurred while none was expected T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants