Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impala compiler hangs (diverges?) compiling parameterized factorial #58

Open
wizzard0 opened this issue Mar 30, 2017 · 6 comments
Open

Comments

@wizzard0
Copy link

wizzard0 commented Mar 30, 2017

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));
})()
@wizzard0
Copy link
Author

wizzard0 commented Mar 30, 2017

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
}

@leissa
Copy link
Member

leissa commented Mar 30, 2017

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

@wizzard0
Copy link
Author

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?

@leissa
Copy link
Member

leissa commented Mar 30, 2017

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

@wizzard0
Copy link
Author

Yep it works then! Thanks a lot!

@leissa
Copy link
Member

leissa commented Mar 31, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants