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

Fat Struct optimizations are incorrect #90

Open
manojo opened this issue May 22, 2015 · 0 comments
Open

Fat Struct optimizations are incorrect #90

manojo opened this issue May 22, 2015 · 0 comments
Labels

Comments

@manojo
Copy link
Collaborator

manojo commented May 22, 2015

See https://gist.github.com/manojo/2e378e7128b13c84f29e for runnable test case.

Suppose we want to generate code for a certain struct Box[T], with the constructor def mkBox[T: Manifest](t: Rep[T]); Rep[Box[T]]. Given the following code:

val someCond: Rep[Boolean] = //dynamic condition
if (someCond) mkBox(2)
else if (someCond) mkBox(7)
else mkBox(0)

If mixed in with the optimisation StructFatExpOptCommon, the generated code contains compile-time errors. Also, the generated code contains only one test for someCond: in the positive branch for that condition, both computations mkBox(2) and mkBox(7) are inlined. This is not desirable in general, and therefore should not be a default "optimisation". Consider a more real-life case:

val someCond: Rep[Boolean] = ...
val anOption: Rep[Option[Int]] = if (someCond) /* complex computation yielding Some */ else None
if (anOption.isDefined) anOption 
else {
   if (someCond) /* complex computation2 yielding Some */
   else None
}

We only want the complex computation 2 to be inlined in the failure branch of the anOption. Using StructFatExpOptCommon we will arrive at a similar problem as above, effectively breaking the semantics of Option.

I am not fully confident in understanding StructExpFat and IfThenElseFat to propose a solution myself, unfortunately.

@manojo manojo added the bug label May 22, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant