AnyDSL/impala

impala compiler hangs (diverges?) compiling parameterized factorial

wizzard0 opened this issue · 6 comments

Code:
Note there are no specialization annotations (@), adding halt annotations ($) doesnt seem to help either.

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

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

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 }
}

This same code is trivially runnable in JS console:

(function(){
    var s=(a,b)=>a-b;
    var s1=(a)=>s(a,1);
    function fac_rec(n, muter){
    if(n<=0){ return 1} else {return n*fac_rec(muter(n),muter)}
	}
	console.log(fac_rec(5,s1));
})()

Interestingly, non-recursive version gets collapsed into "return 120" even without adding any @ annotations

fn fac_iter(n : int, muter: fn(int) -> int) -> int {

 	let mut acc = 1;
 	let mut iter = n;
    while (iter > 1) {
        acc = acc * iter;
        iter = muter(iter);
    }
    acc
}

This, is some new stuff I'm working on. Works in thorin's eurollvm branch.

Ah, I see. I built AnyDSL using the provided "setup.sh". Is it enough to just checkout the thorin/eurollvm, or shall I modify config.sh/other places too?

just checkout eurollvm branch in thorin and re-fire setup.sh

Yep it works then! Thanks a lot!

I wouldn't close this one until we merge to master. There are still a couple of regressions.