Stream: general

Topic: generator resume args segfaults


Jake Goulding (Feb 10 2020 at 18:47, on Zulip):
#![feature(generators, generator_trait)]

use std::{
    io,
    ops::{Generator, GeneratorState},
};

fn my_scenario() -> impl Generator<String, Yield = &'static str, Return = String> {
    |_arg: String| {
        let my_name = yield "What is your name?";
        let my_mood = yield "How are you feeling?";
        format!("{} is {}", my_name.trim(), my_mood.trim())
    }
}

fn main() {
    let mut my_session = Box::pin(my_scenario());

    loop {
        let mut line = String::new();

        match my_session.as_mut().resume(line) {
            GeneratorState::Yielded(prompt) => {
                println!("{}", prompt);
            }
            GeneratorState::Complete(v) => {
                println!("{}", v);
                break;
            }
        }

        line = String::new();
        io::stdin().read_line(&mut line).unwrap();
    }
}
./target/debug/example
What is your name?
Hello
How are you feeling?
world
zsh: segmentation fault  ./target/debug/so
Jake Goulding (Feb 10 2020 at 18:48, on Zulip):

Since this is so new, I expect issues; where are we talking about generators nowadays?

Jonas Schievink (Feb 10 2020 at 19:39, on Zulip):

Nice catch!

Jake Goulding (Feb 10 2020 at 19:49, on Zulip):

@Jonas Schievink is it? Should I go ahead and report it?

Jonas Schievink (Feb 10 2020 at 19:50, on Zulip):

Sure :)

Jake Goulding (Feb 10 2020 at 19:51, on Zulip):

Can do!

Jake Goulding (Feb 10 2020 at 19:57, on Zulip):

https://github.com/rust-lang/rust/issues/69039

Jake Goulding (Feb 11 2020 at 19:32, on Zulip):

Is it bad if I have a little hope that I discovered a massive miscompilation issue?

Jonas Schievink (Feb 11 2020 at 20:09, on Zulip):

No, finding miscompilations is always good :)

Last update: Jun 07 2020 at 10:40UTC