AnyDSL/impala

Ordering problems in IR construction of nested functions

klaasb opened this issue · 1 comments

Impala IR generation fails when an inner function (indirectly) depends on code in the body of the enclosing function. Seems like code for the body is generated after the inner functions are.

fn f(b: bool, i: int) -> int {
    fn F() -> ! { r(i-1) }
    fn T() -> ! { r(i) }
    let ret : fn(int) -> ! = return;
    fn r(x: int) -> ! { ret(x) }
    if (b) {
        T()
    } else {
        F()
    }
}

fn main() -> int {
    f(true, 5)
}

Yields the following error:

impala: .../thorin/src/thorin/def.cpp:34: void thorin::Def::set_op(size_t, const thorin::Def*):
  Assertion `def && "setting null pointer"' failed.
zsh: abort (core dumped)  impala --emit-thorin codegen/bind_ret.impala

When moving lines defining fn F and fn T behind fn r this works.

This works now on master since we removed the SSA-construction phase.