AnyDSL / thorin

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

app node argument has type fn[…] but the callee was expecting closure […] #159

Open michael-kenzel opened 3 months ago

michael-kenzel commented 3 months ago

This bug seems to only trigger on Windows (possibly only when built with MSVC).

The following example will reproduce the bug (compile with --emit-llvm, removing pretty much anything makes the bug disappear):

// any fewer functions will not trigger the bug
// any change to the type of any function makes the bug disappear as well
#[import(name = "A")] fn A(&mut u64, u64) -> u64;
#[import(name = "B")] fn B(&mut i32, i32) -> i32;
#[import(name = "C")] fn C(&mut u32, u32) -> u32;
#[import(name = "D")] fn D(&mut u64, u64) -> u64;

struct thing {
    A: fn() -> (),
    B: fn() -> (),
    C: fn() -> (),
    D: fn() -> (),
}

fn @wrap[T](f: fn(&mut T, T) -> T) {
    @|| -> () {}
}

fn @invoke(body: fn(thing) -> ()) -> () {
    @body(thing {
        A = wrap[u64](A),
        B = wrap[i32](B),
        C = wrap[u32](C),
        D = wrap[u64](D),
    })
}

#[export]
fn print_info(_device: i32) {
    invoke(|_|{});
}

#[export]
fn run(_device: i32, _argc: i32, _argv: &mut u8) {
    invoke(|_|{});
}

results in

assertion 'pt == at' failed in src\thorin\continuation.cpp:57: app node argument wrap_892(run_1534.run_1535, A_1555, cont_901) has type fn[mem, pu64*, pu64, fn[mem, pu64]] but the callee was expecting closure [mem, pu64*, pu64, fn[mem, pu64]]
Hugobros3 commented 3 months ago

Can you provide a commit hash?

michael-kenzel commented 3 months ago

thorin: fb0f72189c16826f69ad947fbf197ebac3cc520c artic: 0f50091011f2bf82efd460264f2f40781a85f72b runtime: 5c1a78c07cbeaea16fd61c73e92fd7112dd62ab7