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

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

Closed
wizzard0 opened this issue Mar 30, 2017 · 2 comments

Comments

@wizzard0
Copy link

wizzard0 commented Mar 30, 2017

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.

@wizzard0 wizzard0 changed the title [eurollvm branch] assertion failed compiling factorial [eurollvm branch] assertion failed compiling generic function call from recursive function Mar 30, 2017
@wizzard0
Copy link
Author

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?

@leissa
Copy link
Member

leissa commented Mar 31, 2017

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

Duplicate of issue #27

@leissa leissa closed this as completed Mar 31, 2017
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