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

Implement --unpretty mir #31656

Merged
merged 1 commit into from
Feb 15, 2016
Merged

Implement --unpretty mir #31656

merged 1 commit into from
Feb 15, 2016

Conversation

jonas-schievink
Copy link
Contributor

This allows obtaining a textual MIR dump for individual items or all items in the crate.

I haven't added any tests since I'm too lazy this is an unstable debugging option, but I'll add one if required.

MIR for a single function can now be dumped using rustc -Zunstable-options --unpretty mir=my_function and no longer requires the use of in-source #[rustc_mir] attributes.

Blocks rust-lang/rust-playpen#154 (if MIR dump support from the playpen is even wanted).

Example output:

fn main() {
    let x = Some(0);
    x.unwrap_or_else(|| 1);
}
MIR for expr || 1 (id=16)
fn(arg0: [closure@test.rs:3:22: 3:26]) -> i32 {
    let mut tmp0: ();

    bb0: {
        return = const 1;
        goto -> bb1;
    }

    bb1: {
        return;
    }
}
MIR for fn main::main (id=4)
fn() -> () {
    let var0: core::option::Option<i32>; // x
    let mut tmp0: ();
    let mut tmp1: i32;
    let mut tmp2: core::option::Option<i32>;
    let mut tmp3: [closure@test.rs:3:22: 3:26];

    bb0: {
        var0 = core::option::Option::Some(const 0);
        tmp2 = var0;
        tmp3 = [closure@test.rs:3:22: 3:26];
        tmp1 = core::option::Option<T>::unwrap_or_else(tmp2, tmp3) -> bb2;
    }

    bb1: {
        return;
    }

    bb2: {
        drop(tmp1) -> bb3;
    }

    bb3: {
        return = ();
        goto -> bb1;
    }
}

@rust-highfive
Copy link
Collaborator

r? @arielb1

(rust_highfive has picked a reviewer for you, use r? to override)

let mir_map = mir_map.unwrap();

for (nodeid, mir) in &mir_map.map {
try!(writeln!(out, "MIR for {}", tcx.map.node_to_string(*nodeid)));
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I personally think the MIR pretty writer should be adapted to somehow work on MIR maps by e.g. outputting

fn main::main() -> ... {
...
}

for functions and

λ main::main::1(... {
}

for closures as well as improving the way closures are printed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. That would require passing both the HIR and MIR map, as well as some custom formatting, so I'll leave that to another PR.

@arielb1
Copy link
Contributor

arielb1 commented Feb 14, 2016

r? @nrc

@rust-highfive rust-highfive assigned nrc and unassigned arielb1 Feb 14, 2016
@nrc
Copy link
Member

nrc commented Feb 14, 2016

@bors: r+

@bors
Copy link
Contributor

bors commented Feb 14, 2016

📌 Commit 67aa7b2 has been approved by nrc

bors added a commit that referenced this pull request Feb 15, 2016
This allows obtaining a textual MIR dump for individual items or all items in the crate.

I haven't added any tests since ~~I'm too lazy~~ this is an unstable debugging option, but I'll add one if required.

MIR for a single function can now be dumped using `rustc -Zunstable-options --unpretty mir=my_function` and no longer requires the use of in-source `#[rustc_mir]` attributes.

Blocks rust-lang/rust-playpen#154 (if MIR dump support from the playpen is even wanted).

Example output:
```rust
fn main() {
    let x = Some(0);
    x.unwrap_or_else(|| 1);
}
```

```
MIR for expr || 1 (id=16)
fn(arg0: [closure@test.rs:3:22: 3:26]) -> i32 {
    let mut tmp0: ();

    bb0: {
        return = const 1;
        goto -> bb1;
    }

    bb1: {
        return;
    }
}
MIR for fn main::main (id=4)
fn() -> () {
    let var0: core::option::Option<i32>; // x
    let mut tmp0: ();
    let mut tmp1: i32;
    let mut tmp2: core::option::Option<i32>;
    let mut tmp3: [closure@test.rs:3:22: 3:26];

    bb0: {
        var0 = core::option::Option::Some(const 0);
        tmp2 = var0;
        tmp3 = [closure@test.rs:3:22: 3:26];
        tmp1 = core::option::Option<T>::unwrap_or_else(tmp2, tmp3) -> bb2;
    }

    bb1: {
        return;
    }

    bb2: {
        drop(tmp1) -> bb3;
    }

    bb3: {
        return = ();
        goto -> bb1;
    }
}
```
@bors
Copy link
Contributor

bors commented Feb 15, 2016

⌛ Testing commit 67aa7b2 with merge 7ce4afb...

@bors bors merged commit 67aa7b2 into rust-lang:master Feb 15, 2016
@jonas-schievink jonas-schievink deleted the mirdump branch February 16, 2016 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants