AnyDSL / thorin

The Higher-Order Intermediate Representation
https://anydsl.github.io
GNU Lesser General Public License v3.0
151 stars 15 forks source link

Recursive function calls using multi-threading triggers assertion #129

Open stlemme opened 1 year ago

stlemme commented 1 year ago
//minified repro sample
fn rec_func_wrapper(n: i32) -> i32 {
    // an @ for rec_func() does not trigger the assertion, but causes full unrolling of the recursion
    fn rec_func(x: i32) -> i32 {
        if x == 0 {
            1
        } else {
            let buffer = alloc_cpu(sizeof[i32]());
            let data = buffer.data as &mut [i32];

            // removing the threading logic and computing rec_func(x-1) directly does not show the issue
            let task = spawn(|| {
                data(0) = rec_func(x-1);
            });

            let tid = task();

            sync(tid);

            let result = data(0);
            release(buffer);

            if result > 0 { 1 } else { 0 }
        }
    }

    rec_func(n)
}

#[export]
fn main() -> i32 {
    let t = rec_func_wrapper(5);

    if t > 0 { 0 } else { -1 }
}

triggers Assertion failed: odef->op(i) != odef, file D:\Projects\anydsl\thorin\src\thorin\transform\importer.cpp, line 80

and in previous versions of thorin this ended up with a stack overflow.