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

RFC: Can we make drop glue for recursive types not stack overflow? #686

Open
steveklabnik opened this issue Jan 21, 2015 · 1 comment

Comments

@steveklabnik
Copy link
Member

commented Jan 21, 2015

Issue by bblum
Thursday Aug 08, 2013 at 20:01 GMT

For earlier discussion, see rust-lang/rust#8399

This issue was labelled with: A-codegen, B-RFC, E-hard, I-wishlist in the Rust repository


Example 2014-02-23

struct Foo { data: int, next: Option<~Foo> }

fn main() {
    let mut foo = Some(~Foo { data: 0, next: None });
    for i in range(0, 17_000_000) {
        if i % 1000000 == 0 {
            error!("{}", i);
        }
        foo = Some(~Foo { data: i, next: foo.take() });
    }
}

Original example

use std::cell::Cell;

struct Foo { data: int, next: Option<~Foo> }

fn main() {
    let foo = Cell::new(Foo { data: 0, next: None });
    let mut i = 0;
    do 17_000_000.times {
        i += 1;
        if i % 1000000 == 0 {
            error!("%d", i);
        }
        foo.put_back(Foo { data: i, next: Some(~foo.take()) });
    }
}
@aidanhs

This comment has been minimized.

Copy link
Member

commented Dec 13, 2016

Updated example:

struct Foo { data: usize, next: Option<Box<Foo>> }

fn main() {
    let mut foo = Some(Box::new(Foo { data: 0, next: None }));
    for i in 1..17_000_000 {
        if i % 1_000_000 == 0 {
            panic!("{}", i);
        }
        foo = Some(Box::new(Foo { data: i, next: foo.take() }));
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.