compiling-to-categories / concat

Compiling to Categories
http://conal.net/papers/compiling-to-categories
BSD 3-Clause "New" or "Revised" License
436 stars 50 forks source link

Plugin diverges on function composition #49

Open jyp opened 5 years ago

jyp commented 5 years ago

The following call does not terminate:

(toCcc (\f g x -> f (g x)))

When enabling the trace, one sees that the generated term gets larger and larger.

conal commented 5 years ago

Thanks. Do you have a complete example I can try out? Is your example as polymorphic as it looks here, including in the target category?

jyp commented 5 years ago

This is literally the first example I tried to test the system, I was not trying to do anything useful. Here is the whole program:

{-# OPTIONS_GHC -fplugin=ConCat.Plugin #-}
{-# OPTIONS_GHC -fplugin-opt=ConCat.Plugin:trace #-}

import ConCat.AltCat
import ConCat.Rebox
import ConCat.Category
import ConCat.Syntactic (render)

main :: IO ()
main = putStrLn $ render (toCcc (\f g x -> f (g (x))))
conal commented 5 years ago

Thanks. Where is comp defined, and how are you compiling?

jyp commented 5 years ago

I had pasted the wrong version and fixed it in a ninja edit. Essentially comp is function composition. See github for the corrected full program. Concat version is github from the day of the report. ghc is 8.4.4. Other packages come from nixos 18.03.

conal commented 5 years ago

Thanks. I'm seeing the behavior you described. I generally compile monomorphic type-specializations of polymorphic functions. In this case, it looks like the plugin isn't finding a suitable transformation, so it's inlining and hoping for the best, which is certainly the wrong choice here.