Skip to content

Commit

Permalink
refactor(common): Debug-print spans more compactly (#8746)
Browse files Browse the repository at this point in the history
**Description:**

`dbg!()` output on ASTs is kinda verbose,

```rs
ExprStmt {
    span: Span {
        lo: BytePos(
            37,
        ),
        hi: BytePos(
            50,
        ),
        ctxt: #0,
    },
    expr: Lit(
        Str(
            Str {
                span: Span {
                    lo: BytePos(
                        37,
                    ),
                    hi: BytePos(
                        49,
                    ),
                    ctxt: #0,
                },
                value: "use strict",
                raw: Some(
                    "\"use strict\"",
                ),
            },
        ),
    ),
}
```

A lot of the space is wasted on spans — 9 lines per span, even though
it's pretty much unimportant cruft. This PR changes that to just one
line per span:

```rs
ExprStmt {
    span: 37..50#0,
    expr: Lit(
        Str(
            Str {
                span: 37..49#0,
                value: "use strict",
                raw: Some(
                    "\"use strict\"",
                ),
            },
        ),
    ),
}
```

While not a statistically meaningful measurement, in my tests (sample
size = 1) this change reduces the `dbg!()` of a 1103-byte script from
5597 to 2885 lines, which is a 48% reduction. In `{:?}` mode it goes
from 40034 to 25457 chars, or 37% reduction.
  • Loading branch information
Kyuuhachi authored Mar 17, 2024
1 parent 1240b88 commit f2300da
Show file tree
Hide file tree
Showing 223 changed files with 3,904 additions and 35,500 deletions.
200 changes: 20 additions & 180 deletions crates/jsdoc/tests/fixtures/abstracttag.debug
Original file line number Diff line number Diff line change
@@ -1,60 +1,20 @@
[
JsDoc {
span: Span {
lo: BytePos(
1,
),
hi: BytePos(
1,
),
ctxt: #0,
},
span: 1..1#0,
description: Text {
span: Span {
lo: BytePos(
1,
),
hi: BytePos(
1,
),
ctxt: #0,
},
span: 1..1#0,
value: "",
},
tags: [
TagItem {
span: Span {
lo: BytePos(
1,
),
hi: BytePos(
12,
),
ctxt: #0,
},
span: 1..12#0,
tag_name: Text {
span: Span {
lo: BytePos(
1,
),
hi: BytePos(
12,
),
ctxt: #0,
},
span: 1..12#0,
value: "constructor",
},
tag: Class(
ClassTag {
span: Span {
lo: BytePos(
1,
),
hi: BytePos(
12,
),
ctxt: #0,
},
span: 1..12#0,
ty: None,
name: None,
},
Expand All @@ -63,122 +23,42 @@
],
},
JsDoc {
span: Span {
lo: BytePos(
46,
),
hi: BytePos(
46,
),
ctxt: #0,
},
span: 46..46#0,
description: Text {
span: Span {
lo: BytePos(
46,
),
hi: BytePos(
46,
),
ctxt: #0,
},
span: 46..46#0,
value: "",
},
tags: [
TagItem {
span: Span {
lo: BytePos(
46,
),
hi: BytePos(
54,
),
ctxt: #0,
},
span: 46..54#0,
tag_name: Text {
span: Span {
lo: BytePos(
46,
),
hi: BytePos(
54,
),
ctxt: #0,
},
span: 46..54#0,
value: "abstract",
},
tag: Abstract(
AbstractTag {
span: Span {
lo: BytePos(
46,
),
hi: BytePos(
54,
),
ctxt: #0,
},
span: 46..54#0,
},
),
},
],
},
JsDoc {
span: Span {
lo: BytePos(
100,
),
hi: BytePos(
100,
),
ctxt: #0,
},
span: 100..100#0,
description: Text {
span: Span {
lo: BytePos(
100,
),
hi: BytePos(
100,
),
ctxt: #0,
},
span: 100..100#0,
value: "",
},
tags: [
TagItem {
span: Span {
lo: BytePos(
100,
),
hi: BytePos(
111,
),
ctxt: #0,
},
span: 100..111#0,
tag_name: Text {
span: Span {
lo: BytePos(
100,
),
hi: BytePos(
111,
),
ctxt: #0,
},
span: 100..111#0,
value: "constructor",
},
tag: Class(
ClassTag {
span: Span {
lo: BytePos(
100,
),
hi: BytePos(
111,
),
ctxt: #0,
},
span: 100..111#0,
ty: None,
name: None,
},
Expand All @@ -187,61 +67,21 @@
],
},
JsDoc {
span: Span {
lo: BytePos(
150,
),
hi: BytePos(
150,
),
ctxt: #0,
},
span: 150..150#0,
description: Text {
span: Span {
lo: BytePos(
150,
),
hi: BytePos(
150,
),
ctxt: #0,
},
span: 150..150#0,
value: "",
},
tags: [
TagItem {
span: Span {
lo: BytePos(
150,
),
hi: BytePos(
157,
),
ctxt: #0,
},
span: 150..157#0,
tag_name: Text {
span: Span {
lo: BytePos(
150,
),
hi: BytePos(
157,
),
ctxt: #0,
},
span: 150..157#0,
value: "virtual",
},
tag: Abstract(
AbstractTag {
span: Span {
lo: BytePos(
150,
),
hi: BytePos(
157,
),
ctxt: #0,
},
span: 150..157#0,
},
),
},
Expand Down
Loading

0 comments on commit f2300da

Please sign in to comment.