Does this stack overflow for anyone else?

fn test_01() {
    let mut ans = im::Vector::new();

    for i in 0..10_000 {
        ans.push_back(1);}
    ans.push_back(2);
    for i in 0..10_000 {
        ans.push_back(1);}

    ans.sort_by(|lhs, rhs| lhs.cmp(rhs));}

Does this stackoverflow for anyone else?

I am running on x86_64 linux

rustc --version
rustc 1.51.0 (2fd73fabe 2021-03-23)

using dependency:

im = { version = "15.0.0", features = ["serde"] }
1 Like

Yes, it stack overflows for me as well. My guess is that this is because the destructor ends up recursing 10000 times. See this post for a similar situation with linked lists.

Also, please rustfmt your code before you post it.

2 Likes

Thanks for verifying.

Have you run this under gdb? For me, it points to src/sort.rs:59, a line having to deal with picking the pivot.

No, I haven't. It was just a guess based on the fact that im uses a tree structure internally.

sort_by does indeed recurse:
https://docs.rs/im/15.0.0/src/im/sort.rs.html#169

Sounds like you have to file a bug report.

2 Likes