AnyDSL/impala

[eurollvm branch] assertion failed compiling generic function call from recursive function

wizzard0 opened this issue · 2 comments

I improved the example from #58 a bit more :)

fn subber(a: int, b: int) -> int {
	a - b
}

fn invocator[T, TR](a:fn(T) -> TR, b: T) -> TR {
	a(b)
}

fn fac_rec(n : int, muter: fn(int) -> int) -> int {
	let swrap = |x: int| invocator(muter,x);
    if (n <= 0) {
        1
    } else {
    	let nn = swrap(n);
        n * fac_rec(nn, swrap)
    }
}

fn fac_nrec(n : int) -> int {
	let subber1 = |x: int| subber(x, 1);
	@fac_rec(n, subber1)
}

fn main() -> int {
	fac_nrec(5)
    //if @fac_rec(5) == 120 { 0 } else { 1 }
}

and this gets me this assertion:

user@linux-thorin:~/anydsl/impala/test$ impala --emit-llvm -O3 codegen/fac_rec.impala
impala: /home/user/anydsl/impala/src/impala/emit.cpp:539: virtual const thorin::Def* impala::TypeAppExpr::remit(impala::CodeGen&) const: Assertion `false && "TODO"' failed.
Aborted (core dumped)

... and i'm not really sure whether this is a bug or i'm trying to compile something strange :)

UPD: specifying concrete types gets rid of assertion, i'm impressed.

Hmm, interestingly if I decrement not by 1 but by parameter read from stdin -- then all closures are still eliminated, but the recursion is no longer unrolled into a loop.

Why does that happen this way?

Oh, plz don't use polymorphism. It's currently broken.

Duplicate of issue #27