AnyDSL / thorin

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

Assertion failed: cont_scope.has_free_params() #160

Open michael-kenzel opened 2 weeks ago

michael-kenzel commented 2 weeks 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):

#[import(cc = "thorin")] fn cuda(_dev: i32, _grid: (i32, i32, i32), _block: (i32, i32, i32), _body: fn() -> ()) -> ();

enum needs_to_be_here_to_trigger_the_bug {
    A, B, C, D  // any fewer members will not trigger the bug
}

fn @no_bug_without_me_either(need: needs_to_be_here_to_trigger_the_bug) -> u32 {
    match need {
        needs_to_be_here_to_trigger_the_bug::A => 1,
        needs_to_be_here_to_trigger_the_bug::B => 2,
        needs_to_be_here_to_trigger_the_bug::C => 3,
        needs_to_be_here_to_trigger_the_bug::D => 4,
    }
}

struct G {
    xxx: fn(fn(C) -> ()) -> fn() -> (),
}

struct C {
}

fn @invoke(body: fn(C) -> ()) -> () {
    @body(C {})
}

fn @launch(device: i32, body: fn(G) -> ()) -> () {
    cuda(device, (1, 1, 1), (1, 1, 1), @|| @body(G {
        xxx = @|body| @|| invoke(body),
    }))
}

struct Device {
    launch: fn(fn(G) -> ()) -> (),
}

fn @createDevice(device: i32) {
    Device {
        launch = @|body| launch(device, body)
    }
}

#[export]
fn benchmark_print_info(device: i32) {
    createDevice(device);
    0
}

#[export]
fn benchmark_run(device: i32, argc: i32, argv: &mut u8) {
    createDevice(device);
}

results in

Assertion failed: cont_scope.has_free_params(), file src\thorin\analyses\scope.cpp, line 93
Hugobros3 commented 2 weeks ago

Can you provide a commit hash?

michael-kenzel commented 2 weeks ago

thorin: fb0f72189c16826f69ad947fbf197ebac3cc520c artic: 0f50091011f2bf82efd460264f2f40781a85f72b runtime: 5c1a78c07cbeaea16fd61c73e92fd7112dd62ab7