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

Add -Z unpretty flag for the THIR #82860

Merged
merged 2 commits into from
Mar 12, 2021
Merged

Conversation

LeSeulArtichaut
Copy link
Contributor

This adds a new perma-unstable flag, -Zunpretty=thir-tree, that dumps the raw THIR tree for each body in the crate.

Implements the THIR part of MCP rust-lang/compiler-team#408, helps with rust-lang/rustc-dev-guide#1062.
Depends on #82495, blocked on that. Only the two last commits are added by this PR.
r? @spastorino cc @estebank

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 7, 2021
@LeSeulArtichaut
Copy link
Contributor Author

For our test program:

pub fn is_awesome(name: &str) -> bool {
    matches!(name, "Rust" | "Ferris")
}

This gives the following output:

Output
DefId(0:3 ~ test[8787]::is_awesome):
Expr {
    ty: bool,
    temp_lifetime: Some(
        Node(17),
    ),
    span: test.rs:1:39: 3:2 (#0),
    kind: Scope {
        region_scope: Destruction(17),
        lint_level: Inherited,
        value: Expr {
            ty: bool,
            temp_lifetime: Some(
                Node(17),
            ),
            span: test.rs:1:39: 3:2 (#0),
            kind: Scope {
                region_scope: Node(17),
                lint_level: Explicit(
                    HirId {
                        owner: DefId(0:3 ~ test[8787]::is_awesome),
                        local_id: 17,
                    },
                ),
                value: Expr {
                    ty: bool,
                    temp_lifetime: Some(
                        Node(17),
                    ),
                    span: test.rs:1:39: 3:2 (#0),
                    kind: Block {
                        body: Block {
                            targeted_by_break: false,
                            region_scope: Node(16),
                            opt_destruction_scope: None,
                            span: test.rs:1:39: 3:2 (#0),
                            stmts: [],
                            expr: Some(
                                Expr {
                                    ty: bool,
                                    temp_lifetime: Some(
                                        Node(17),
                                    ),
                                    span: /Users/tous/Documents/Dev/rust/library/core/src/macros/mod.rs:319:9: 322:10 (#6),
                                    kind: Scope {
                                        region_scope: Node(15),
                                        lint_level: Explicit(
                                            HirId {
                                                owner: DefId(0:3 ~ test[8787]::is_awesome),
                                                local_id: 15,
                                            },
                                        ),
                                        value: Expr {
                                            ty: bool,
                                            temp_lifetime: Some(
                                                Node(17),
                                            ),
                                            span: /Users/tous/Documents/Dev/rust/library/core/src/macros/mod.rs:319:9: 322:10 (#6),
                                            kind: Match {
                                                scrutinee: Expr {
                                                    ty: &str,
                                                    temp_lifetime: Some(
                                                        Node(17),
                                                    ),
                                                    span: test.rs:2:14: 2:18 (#0),
                                                    kind: Scope {
                                                        region_scope: Node(4),
                                                        lint_level: Explicit(
                                                            HirId {
                                                                owner: DefId(0:3 ~ test[8787]::is_awesome),
                                                                local_id: 4,
                                                            },
                                                        ),
                                                        value: Expr {
                                                            ty: &str,
                                                            temp_lifetime: Some(
                                                                Node(17),
                                                            ),
                                                            span: test.rs:2:14: 2:18 (#0),
                                                            kind: VarRef {
                                                                id: HirId {
                                                                    owner: DefId(0:3 ~ test[8787]::is_awesome),
                                                                    local_id: 2,
                                                                },
                                                            },
                                                        },
                                                    },
                                                },
                                                arms: [
                                                    Arm {
                                                        pattern: Pat {
                                                            ty: &str,
                                                            span: /Users/tous/Documents/Dev/rust/library/core/src/macros/mod.rs:320:16: 320:24 (#6),
                                                            kind: Or {
                                                                pats: [
                                                                    Pat {
                                                                        ty: &str,
                                                                        span: test.rs:2:20: 2:26 (#0),
                                                                        kind: Constant {
                                                                            value: Const {
                                                                                ty: &str,
                                                                                val: Value(
                                                                                    Slice {
                                                                                        data: Allocation {
                                                                                            bytes: [
                                                                                                82,
                                                                                                117,
                                                                                                115,
                                                                                                116,
                                                                                            ],
                                                                                            relocations: Relocations(
                                                                                                SortedMap {
                                                                                                    data: [],
                                                                                                },
                                                                                            ),
                                                                                            init_mask: InitMask {
                                                                                                blocks: [
                                                                                                    15,
                                                                                                ],
                                                                                                len: Size {
                                                                                                    raw: 4,
                                                                                                },
                                                                                            },
                                                                                            size: Size {
                                                                                                raw: 4,
                                                                                            },
                                                                                            align: Align {
                                                                                                pow2: 0,
                                                                                            },
                                                                                            mutability: Not,
                                                                                            extra: (),
                                                                                        },
                                                                                        start: 0,
                                                                                        end: 4,
                                                                                    },
                                                                                ),
                                                                            },
                                                                        },
                                                                    },
                                                                    Pat {
                                                                        ty: &str,
                                                                        span: test.rs:2:29: 2:37 (#0),
                                                                        kind: Constant {
                                                                            value: Const {
                                                                                ty: &str,
                                                                                val: Value(
                                                                                    Slice {
                                                                                        data: Allocation {
                                                                                            bytes: [
                                                                                                70,
                                                                                                101,
                                                                                                114,
                                                                                                114,
                                                                                                105,
                                                                                                115,
                                                                                            ],
                                                                                            relocations: Relocations(
                                                                                                SortedMap {
                                                                                                    data: [],
                                                                                                },
                                                                                            ),
                                                                                            init_mask: InitMask {
                                                                                                blocks: [
                                                                                                    63,
                                                                                                ],
                                                                                                len: Size {
                                                                                                    raw: 6,
                                                                                                },
                                                                                            },
                                                                                            size: Size {
                                                                                                raw: 6,
                                                                                            },
                                                                                            align: Align {
                                                                                                pow2: 0,
                                                                                            },
                                                                                            mutability: Not,
                                                                                            extra: (),
                                                                                        },
                                                                                        start: 0,
                                                                                        end: 6,
                                                                                    },
                                                                                ),
                                                                            },
                                                                        },
                                                                    },
                                                                ],
                                                            },
                                                        },
                                                        guard: None,
                                                        body: Expr {
                                                            ty: bool,
                                                            temp_lifetime: Some(
                                                                Node(11),
                                                            ),
                                                            span: /Users/tous/Documents/Dev/rust/library/core/src/macros/mod.rs:320:48: 320:52 (#6),
                                                            kind: Scope {
                                                                region_scope: Destruction(11),
                                                                lint_level: Inherited,
                                                                value: Expr {
                                                                    ty: bool,
                                                                    temp_lifetime: Some(
                                                                        Node(11),
                                                                    ),
                                                                    span: /Users/tous/Documents/Dev/rust/library/core/src/macros/mod.rs:320:48: 320:52 (#6),
                                                                    kind: Scope {
                                                                        region_scope: Node(11),
                                                                        lint_level: Explicit(
                                                                            HirId {
                                                                                owner: DefId(0:3 ~ test[8787]::is_awesome),
                                                                                local_id: 11,
                                                                            },
                                                                        ),
                                                                        value: Expr {
                                                                            ty: bool,
                                                                            temp_lifetime: Some(
                                                                                Node(11),
                                                                            ),
                                                                            span: /Users/tous/Documents/Dev/rust/library/core/src/macros/mod.rs:320:48: 320:52 (#6),
                                                                            kind: Literal {
                                                                                literal: Const {
                                                                                    ty: bool,
                                                                                    val: Value(
                                                                                        Scalar(
                                                                                            0x01,
                                                                                        ),
                                                                                    ),
                                                                                },
                                                                                user_ty: None,
                                                                                const_id: None,
                                                                            },
                                                                        },
                                                                    },
                                                                },
                                                            },
                                                        },
                                                        lint_level: Explicit(
                                                            HirId {
                                                                owner: DefId(0:3 ~ test[8787]::is_awesome),
                                                                local_id: 10,
                                                            },
                                                        ),
                                                        scope: Node(10),
                                                        span: /Users/tous/Documents/Dev/rust/library/core/src/macros/mod.rs:320:16: 320:52 (#6),
                                                    },
                                                    Arm {
                                                        pattern: Pat {
                                                            ty: &str,
                                                            span: /Users/tous/Documents/Dev/rust/library/core/src/macros/mod.rs:321:13: 321:14 (#6),
                                                            kind: Wild,
                                                        },
                                                        guard: None,
                                                        body: Expr {
                                                            ty: bool,
                                                            temp_lifetime: Some(
                                                                Node(14),
                                                            ),
                                                            span: /Users/tous/Documents/Dev/rust/library/core/src/macros/mod.rs:321:18: 321:23 (#6),
                                                            kind: Scope {
                                                                region_scope: Destruction(14),
                                                                lint_level: Inherited,
                                                                value: Expr {
                                                                    ty: bool,
                                                                    temp_lifetime: Some(
                                                                        Node(14),
                                                                    ),
                                                                    span: /Users/tous/Documents/Dev/rust/library/core/src/macros/mod.rs:321:18: 321:23 (#6),
                                                                    kind: Scope {
                                                                        region_scope: Node(14),
                                                                        lint_level: Explicit(
                                                                            HirId {
                                                                                owner: DefId(0:3 ~ test[8787]::is_awesome),
                                                                                local_id: 14,
                                                                            },
                                                                        ),
                                                                        value: Expr {
                                                                            ty: bool,
                                                                            temp_lifetime: Some(
                                                                                Node(14),
                                                                            ),
                                                                            span: /Users/tous/Documents/Dev/rust/library/core/src/macros/mod.rs:321:18: 321:23 (#6),
                                                                            kind: Literal {
                                                                                literal: Const {
                                                                                    ty: bool,
                                                                                    val: Value(
                                                                                        Scalar(
                                                                                            0x00,
                                                                                        ),
                                                                                    ),
                                                                                },
                                                                                user_ty: None,
                                                                                const_id: None,
                                                                            },
                                                                        },
                                                                    },
                                                                },
                                                            },
                                                        },
                                                        lint_level: Explicit(
                                                            HirId {
                                                                owner: DefId(0:3 ~ test[8787]::is_awesome),
                                                                local_id: 13,
                                                            },
                                                        ),
                                                        scope: Node(13),
                                                        span: /Users/tous/Documents/Dev/rust/library/core/src/macros/mod.rs:321:13: 321:23 (#6),
                                                    },
                                                ],
                                            },
                                        },
                                    },
                                },
                            ),
                            safety_mode: Safe,
                        },
                    },
                },
            },
        },
    },
}


@LeSeulArtichaut LeSeulArtichaut added A-pretty Area: Pretty printing (including `-Z unpretty`) S-blocked Status: Blocked on something else such as an RFC or other implementation work. labels Mar 7, 2021
@bors
Copy link
Contributor

bors commented Mar 9, 2021

☔ The latest upstream changes (presumably #82929) made this pull request unmergeable. Please resolve the merge conflicts.

@LeSeulArtichaut
Copy link
Contributor Author

@spastorino currently doesn't have a lot of time, r? @estebank could you take over the review?

@rust-highfive rust-highfive assigned estebank and unassigned spastorino Mar 10, 2021
@LeSeulArtichaut LeSeulArtichaut removed the S-blocked Status: Blocked on something else such as an RFC or other implementation work. label Mar 11, 2021
@spastorino
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Mar 11, 2021

📌 Commit 6bf4147 has been approved by spastorino

@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 11, 2021
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Mar 11, 2021
…astorino

Add `-Z unpretty` flag for the THIR

This adds a new perma-unstable flag, `-Zunpretty=thir-tree`, that dumps the raw THIR tree for each body in the crate.

Implements the THIR part of MCP rust-lang/compiler-team#408, helps with rust-lang/rustc-dev-guide#1062.
Depends on rust-lang#82495, blocked on that. Only the two last commits are added by this PR.
r? `@spastorino` cc `@estebank`
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Mar 11, 2021
…astorino

Add `-Z unpretty` flag for the THIR

This adds a new perma-unstable flag, `-Zunpretty=thir-tree`, that dumps the raw THIR tree for each body in the crate.

Implements the THIR part of MCP rust-lang/compiler-team#408, helps with rust-lang/rustc-dev-guide#1062.
Depends on rust-lang#82495, blocked on that. Only the two last commits are added by this PR.
r? ``@spastorino`` cc ``@estebank``
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 12, 2021
Rollup of 11 pull requests

Successful merges:

 - rust-lang#80385 (Clarify what `Cell::replace` returns)
 - rust-lang#82571 (Rustdoc Json: Add tests for Reexports, and improve jsondocck)
 - rust-lang#82860 (Add `-Z unpretty` flag for the THIR)
 - rust-lang#82950 (convert slice doc link to intra-doc links)
 - rust-lang#82965 (Add spirv extension handling in compiletest)
 - rust-lang#82966 (update MSYS2 link in README)
 - rust-lang#82979 (Fix "run" button position in error index)
 - rust-lang#83001 (Ignore Vim swap files)
 - rust-lang#83003 (rustdoc: tweak the search index format)
 - rust-lang#83013 (Adjust some `#[cfg]`s to take non-Unix non-Windows operating systems into account)
 - rust-lang#83018 (Reintroduce accidentally deleted assertions.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit f183a3e into rust-lang:master Mar 12, 2021
@rustbot rustbot added this to the 1.52.0 milestone Mar 12, 2021
@LeSeulArtichaut LeSeulArtichaut deleted the unpretty-thir branch March 12, 2021 05:53
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`) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants