Skip to content

Commit

Permalink
Rollup merge of #92924 - dtolnay:pptracing, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
Delete pretty printer tracing

These are left over from 2011. I did not find these helpful at all in my work on https://github.com/dtolnay/prettyplease despite doing significant refactors to this code. Learning what these messages all refer to is harder than putting in your own messages to log exactly what is relevant to specifically the thing that you are working on debugging.
  • Loading branch information
matthiaskrgr committed Jan 18, 2022
2 parents 5a4f474 + fe86dcf commit 262f48e
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 54 deletions.
1 change: 0 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3433,7 +3433,6 @@ version = "0.0.0"
dependencies = [
"rustc_ast",
"rustc_span",
"tracing",
]

[[package]]
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_ast_pretty/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ edition = "2021"
doctest = false

[dependencies]
tracing = "0.1"
rustc_span = { path = "../rustc_span" }
rustc_ast = { path = "../rustc_ast" }
52 changes: 0 additions & 52 deletions compiler/rustc_ast_pretty/src/pp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ use ring::RingBuffer;
use std::borrow::Cow;
use std::collections::VecDeque;
use std::fmt;
use tracing::debug;

/// How to break. Described in more detail in the module docs.
#[derive(Clone, Copy, PartialEq)]
Expand Down Expand Up @@ -193,22 +192,6 @@ impl fmt::Display for Token {
}
}

fn buf_str(buf: &RingBuffer<BufEntry>, left: usize, right: usize, lim: usize) -> String {
let mut i = left;
let mut l = lim;
let mut s = String::from("[");
while i != right && l != 0 {
l -= 1;
if i != left {
s.push_str(", ");
}
s.push_str(&format!("{}={}", buf[i].size, &buf[i].token));
i += 1;
}
s.push(']');
s
}

#[derive(Copy, Clone)]
enum PrintStackBreak {
Fits,
Expand Down Expand Up @@ -267,7 +250,6 @@ impl Default for BufEntry {
impl Printer {
pub fn new() -> Self {
let linewidth = 78;
debug!("Printer::new {}", linewidth);
let mut buf = RingBuffer::new();
buf.advance_right();
Printer {
Expand Down Expand Up @@ -310,16 +292,13 @@ impl Printer {
} else {
self.advance_right();
}
debug!("pp Begin({})/buffer Vec<{},{}>", b.offset, self.left, self.right);
self.scan_push(BufEntry { token: Token::Begin(b), size: -self.right_total });
}

fn scan_end(&mut self) {
if self.scan_stack.is_empty() {
debug!("pp End/print Vec<{},{}>", self.left, self.right);
self.print_end();
} else {
debug!("pp End/buffer Vec<{},{}>", self.left, self.right);
self.advance_right();
self.scan_push(BufEntry { token: Token::End, size: -1 });
}
Expand All @@ -334,18 +313,15 @@ impl Printer {
} else {
self.advance_right();
}
debug!("pp Break({})/buffer Vec<{},{}>", b.offset, self.left, self.right);
self.check_stack(0);
self.scan_push(BufEntry { token: Token::Break(b), size: -self.right_total });
self.right_total += b.blank_space;
}

fn scan_string(&mut self, s: Cow<'static, str>) {
if self.scan_stack.is_empty() {
debug!("pp String('{}')/print Vec<{},{}>", s, self.left, self.right);
self.print_string(s);
} else {
debug!("pp String('{}')/buffer Vec<{},{}>", s, self.left, self.right);
self.advance_right();
let len = s.len() as isize;
self.buf[self.right] = BufEntry { token: Token::String(s), size: len };
Expand All @@ -355,18 +331,8 @@ impl Printer {
}

fn check_stream(&mut self) {
debug!(
"check_stream Vec<{}, {}> with left_total={}, right_total={}",
self.left, self.right, self.left_total, self.right_total
);
if self.right_total - self.left_total > self.space {
debug!(
"scan window is {}, longer than space on line ({})",
self.right_total - self.left_total,
self.space
);
if Some(&self.left) == self.scan_stack.back() {
debug!("setting {} to infinity and popping", self.left);
let scanned = self.scan_pop_bottom();
self.buf[scanned].size = SIZE_INFINITY;
}
Expand All @@ -378,7 +344,6 @@ impl Printer {
}

fn scan_push(&mut self, entry: BufEntry) {
debug!("scan_push {}", self.right);
self.buf[self.right] = entry;
self.scan_stack.push_front(self.right);
}
Expand All @@ -401,11 +366,6 @@ impl Printer {
}

fn advance_left(&mut self) {
debug!(
"advance_left Vec<{},{}>, sizeof({})={}",
self.left, self.right, self.left, self.buf[self.left].size
);

let mut left_size = self.buf[self.left].size;

while left_size >= 0 {
Expand Down Expand Up @@ -465,14 +425,12 @@ impl Printer {
}

fn print_newline(&mut self, amount: isize) {
debug!("NEWLINE {}", amount);
self.out.push('\n');
self.pending_indentation = 0;
self.indent(amount);
}

fn indent(&mut self, amount: isize) {
debug!("INDENT {}", amount);
self.pending_indentation += amount;
}

Expand All @@ -485,40 +443,33 @@ impl Printer {
fn print_begin(&mut self, b: BeginToken, l: isize) {
if l > self.space {
let col = self.margin - self.space + b.offset;
debug!("print Begin -> push broken block at col {}", col);
self.print_stack
.push(PrintStackElem { offset: col, pbreak: PrintStackBreak::Broken(b.breaks) });
} else {
debug!("print Begin -> push fitting block");
self.print_stack.push(PrintStackElem { offset: 0, pbreak: PrintStackBreak::Fits });
}
}

fn print_end(&mut self) {
debug!("print End -> pop End");
self.print_stack.pop().unwrap();
}

fn print_break(&mut self, b: BreakToken, l: isize) {
let top = self.get_top();
match top.pbreak {
PrintStackBreak::Fits => {
debug!("print Break({}) in fitting block", b.blank_space);
self.space -= b.blank_space;
self.indent(b.blank_space);
}
PrintStackBreak::Broken(Breaks::Consistent) => {
debug!("print Break({}+{}) in consistent block", top.offset, b.offset);
self.print_newline(top.offset + b.offset);
self.space = self.margin - (top.offset + b.offset);
}
PrintStackBreak::Broken(Breaks::Inconsistent) => {
if l > self.space {
debug!("print Break({}+{}) w/ newline in inconsistent", top.offset, b.offset);
self.print_newline(top.offset + b.offset);
self.space = self.margin - (top.offset + b.offset);
} else {
debug!("print Break({}) w/o newline in inconsistent", b.blank_space);
self.indent(b.blank_space);
self.space -= b.blank_space;
}
Expand All @@ -528,7 +479,6 @@ impl Printer {

fn print_string(&mut self, s: Cow<'static, str>) {
let len = s.len() as isize;
debug!("print String({})", s);
// assert!(len <= space);
self.space -= len;

Expand All @@ -545,8 +495,6 @@ impl Printer {
}

fn print(&mut self, token: Token, l: isize) {
debug!("print {} {} (remaining line space={})", token, l, self.space);
debug!("{}", buf_str(&self.buf, self.left, self.right, 6));
match token {
Token::Begin(b) => self.print_begin(b, l),
Token::End => self.print_end(),
Expand Down

0 comments on commit 262f48e

Please sign in to comment.