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

Broken MIR with immovable generators #49232

Closed
Nemo157 opened this issue Mar 21, 2018 · 1 comment
Closed

Broken MIR with immovable generators #49232

Nemo157 opened this issue Mar 21, 2018 · 1 comment
Labels
A-coroutines Area: Coroutines C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Nemo157
Copy link
Member

Nemo157 commented Mar 21, 2018

#![feature(conservative_impl_trait)]
#![feature(generators)]
#![feature(generator_trait)]

use std::ops::Generator;

#[derive(Debug)]
pub struct Beacon;

fn listen() -> impl Iterator<Item=Beacon> {
    Some(Beacon).into_iter()
}

pub fn main() -> impl Generator<Yield=(), Return=Result<(), ()>> {
    #[allow(unused_unsafe)]
    unsafe {
        static move || {
            let mut stream = listen();

            loop {
                let beacon = {
                    match stream.next() {
                        Some(e) => e,
                        None => break,
                    }
                };
                println!("Saw beacon {:?}", beacon);
            }

            loop {
                yield ();
            }
        }
    }
}

when compiled with rustc src/lib.rs --crate-type lib gives error:

error: internal compiler error: librustc_mir/transform/generator.rs:495: Broken MIR: generator contains type Beacon in MIR, but typeck only knows about {impl std::iter::Iterator, ()}
  --> src/lib.rs:17:9
   |
17 | /         static move || {
18 | |             let mut stream = listen();
19 | |
20 | |             loop {
...  |
32 | |             }
33 | |         }
   | |_________^

thread 'rustc' panicked at 'Box<Any>', librustc_errors/lib.rs:488:9
note: Run with `RUST_BACKTRACE=1` for a backtrace.

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.26.0-nightly (a04b88d19 2018-03-19) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib
@pietroalbini pietroalbini added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. A-coroutines Area: Coroutines labels Mar 21, 2018
@Zoxc
Copy link
Contributor

Zoxc commented Apr 5, 2018

The problem here is that we don't generate a StorageDead(beacon) instruction when we break from the loop to match the previous StorageLive(beacon), so the beacon variable appears live outside the loop. This can be seen from the MIR of this simpler code:

fn main() {
    loop {
        let beacon = {
            match true {
                false => 4,
                true => break,
            }
        };
        drop(&beacon);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-coroutines Area: Coroutines C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants