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

Avoid a bunch of booleans in favor of Result<(), ErrorGuaranteed> as that more robustly proves that an error has been emitted #126317

Merged
merged 6 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_log/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
tracing = "0.1.28"
tracing-core = "=0.1.30" # FIXME(Nilstrieb) tracing has a deadlock: https://github.com/tokio-rs/tracing/issues/2635
tracing-subscriber = { version = "0.3.3", default-features = false, features = ["fmt", "env-filter", "smallvec", "parking_lot", "ansi"] }
tracing-tree = "0.3.0"
tracing-tree = "0.3.1"
# tidy-alphabetical-end

[dev-dependencies]
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_log/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub struct LoggerConfig {
pub verbose_thread_ids: Result<String, VarError>,
pub backtrace: Result<String, VarError>,
pub wraptree: Result<String, VarError>,
pub lines: Result<String, VarError>,
}

impl LoggerConfig {
Expand All @@ -69,6 +70,7 @@ impl LoggerConfig {
verbose_thread_ids: env::var(format!("{env}_THREAD_IDS")),
backtrace: env::var(format!("{env}_BACKTRACE")),
wraptree: env::var(format!("{env}_WRAPTREE")),
lines: env::var(format!("{env}_LINES")),
}
}
}
Expand Down Expand Up @@ -101,13 +103,19 @@ pub fn init_logger(cfg: LoggerConfig) -> Result<(), Error> {
Err(_) => false,
};

let lines = match cfg.lines {
Ok(v) => &v == "1",
Err(_) => false,
Copy link
Member

Choose a reason for hiding this comment

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

I think a surprising side-effect of this change was to turn off the lines by default?

Even when they are turned on, they look very different... much harder than before to just "move up" and find earlier things on the same level of nesting, since the line is now just a snake that moves left and right with the indentation, it no longer properly shows what nesting level we are getting back to.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

lines were already turned off in an earlier PR by someone else because they broke code folding which allowed you to fold entire sub-spans. After I switched tracing-tree to use the snaky line, you get both the lines (which I find useful) and the code folding, so I made it opt-in. Locally I was replacing | manually with spaces in the last year just to get code folding in IDEs.

Copy link
Member

Choose a reason for hiding this comment

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

What's "code folding"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When you hover over the line numbers in vscode, folding thingies like for directories show up. These are indentation based I think, but in code they may be squirly bracket based

};

let mut layer = tracing_tree::HierarchicalLayer::default()
.with_writer(io::stderr)
.with_ansi(color_logs)
.with_targets(true)
.with_verbose_exit(verbose_entry_exit)
.with_verbose_entry(verbose_entry_exit)
.with_indent_amount(2)
.with_indent_lines(lines)
.with_thread_ids(verbose_thread_ids)
.with_thread_names(verbose_thread_ids);

Expand Down