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

CPS inliner issue with recursive function being mapped #10

Open
SimonAlling opened this issue Feb 22, 2019 · 1 comment
Open

CPS inliner issue with recursive function being mapped #10

SimonAlling opened this issue Feb 22, 2019 · 1 comment
Assignees
Labels
bug trunk related to the trunk branch

Comments

@SimonAlling
Copy link

Greetings from Sweden and Chalmers University of Technology!

I may have found something when exploring parallel arrays in Manticore. Here is a piece of code that works perfectly fine:

fun f n = if n <= 0 then 0 else 1 + f (n - 1)
val xs = [ 1, 2, 3 ]
val _ = map f xs

Here is a similar program with a parallel array and PArray.map instead of a list and the regular map:

(* f same as before *)
val xs = PArray.fromRope (Rope.tabulateSequential (fn x => x) (1, 3))
val _ = PArray.map (fn x => f x) xs

That code also works. But watch what happens when I eta-reduce the mapped function:

val _ = PArray.map f xs

The code doesn't compile anymore:

$ pmlc eta.pml
***** Bogus CPS in Main after inline *****
** unbound variable f<11431>#4.4
** unbound variable f<11431>#4.4 in Apply
** unbound variable f<11431>#4.4
** unbound variable f<11431>#4.4 in Apply
broken CPS dumped to broken-CPS

The dumped file is 1.7 MB, but I can't really extract any useful information from it.

It also turns out that everything works fine if f is not recursive:

fun f n = if n <= 0 then 0 else 1
val xs = PArray.fromRope (Rope.tabulateSequential (fn x => x) (1, 3))
val _ = PArray.map f xs

I'm not an expert, but there seems to be something going on here. What do you think?

@kavon kavon added bug trunk related to the trunk branch labels Mar 8, 2019
@kavon
Copy link
Member

kavon commented Mar 8, 2019

This appears to be hitting on some bug in the expansive inliner that runs on the CPS IR.

A workaround for this right now would be to turn off that particular inliner by passing
-Ccps.enable-inline=false to the compiler. Note that other function inlining will still happen in the compiler.

Thanks for the bug report! I've summarized the cases below for when we can get around to fixing this.

fun nonrecF x = x + 1

fun recF n = if n <= 0 then 0 else 1 + recF (n - 1)

val xs = PArray.fromRope (Rope.tabulateSequential (fn x => x) (1, 3))

(* broken *)
val _ = PArray.map recF xs

(* works if you eta-expand *)
(* val _ = PArray.map (fn x => recF x) xs *)

(* not an issue for non-recursive function *)
(* val _ = PArray.map nonrecF xs *)

@kavon kavon changed the title PArray code not stable under eta reduction CPS inliner issue with recursive function being mapped Mar 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug trunk related to the trunk branch
Projects
None yet
Development

No branches or pull requests

3 participants