compiling-to-categories / concat

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

GHC panic #15

Closed chriseidhof closed 7 years ago

chriseidhof commented 7 years ago

Not sure if this is the appropriate place, but there seems to be a problem with GHC 8.0.2 and the latest code. When building concat-examples, GHC crashes with the following error message:

[1 of 1] Compiling Main             ( test/Examples.hs, .stack-work/dist/x86_64-osx/Cabal-1.24.2.0/build/examples/examples-tmp/Main.o )
ghc: panic! (the 'impossible' happened)
  (GHC version 8.0.2 for x86_64-apple-darwin):
        ccc    
  lam Unhandled \ (eta_ds_Bh
                     :: ((R -> Double, R), (R -> Double, R))) ->
                  case deriv
                         @ (->)
                         @ R
                         @ Double
                         (exl
                            @ (->)
                            @ (R -> Double)
                            @ R
                            $fProductCat(->)
                            (($fYes1ka @ * @ (R -> Double), $fYes1ka @ * @ Double)
                             `cast` ((Sym R:Ok(->)[0] <Double -> Double>_N,
                                      Sym R:Ok(->)[0] <Double>_N)_R
                                     :: ((Yes1 (Double -> Double), Yes1 Double) :: Constraint)
                                        ~R#
                                        ((Ok (->) (Double -> Double),
                                          Ok (->) Double) :: Constraint)))
                            (exl
                               @ (->)
                               @ (R -> Double, R)
                               @ (R -> Double, R)
                               $fProductCat(->)
                               (($fYes1ka @ * @ (R -> Double, R), $fYes1ka @ * @ (R -> Double, R))
                                `cast` ((Sym R:Ok(->)[0] <(Double -> Double, Double)>_N,
                                         Sym R:Ok(->)[0] <(Double -> Double, Double)>_N)_R
                                        :: ((Yes1 (Double -> Double, Double),
                                             Yes1 (Double -> Double, Double)) :: Constraint)
                                           ~R#
                                           ((Ok (->) (Double -> Double, Double),
                                             Ok (->) (Double -> Double, Double)) :: Constraint)))
                               eta_ds_Bh))
                  of wild_00 {
                  }

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

Progress: 22/23
--  While building package concat-examples-0.3.0.0 using:
      /Users/chris/.stack/setup-exe-cache/x86_64-osx/Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 --builddir=.stack-work/dist/x86_64-osx/Cabal-1.24.2.0 build lib:concat-examples test:examples --ghc-options " -ddump-hi -ddump-to-file"
    Process exited with code: ExitFailure 1
conal commented 7 years ago

Oops. I had accidentally left one of my currently experimental/breaking examples exposed in Examples.hs. I just switched back to some working examples. Try again?

chriseidhof commented 7 years ago

Awesome, that did the trick. Thanks @conal !

conal commented 7 years ago

Glad to hear it, @chriseidhof. :) Please let me know if you run into more issues.

I'm always interested in seeing and helping with additional applications. I suspect that most deep DSL embeddings would be improved by switching to the compiling-to-categories approach, in terms of usability, optimizability, and ease of implementation.

chriseidhof commented 7 years ago

Awesome!

We just read your paper for our little functional Swift reading club, and really liked it. The fact that source-level transformations are necessary (and that we've been doing it wrong with trying to write EDSLs) was interesting to me.

I've struggled in the past with implementing a bunch of EDSLs in Haskell, and specifically the fact that you can't look "inside" a function when trying to compile. I'll have to go back and rethink some of the work I did. It could be interesting to see if it's possible to do defunctionalization. Also, I could imagine that you can target other programming languages (e.g. write in Haskell and extract Swift/Javascript or even C) using CCC's.

In reading the paper, I struggled a bit with understanding some of the applications, but that's because I lack knowledge around e.g. linear algebra.

Many thanks for writing such a readable paper and building all of this. It shows that a lot of work went into this.

conal commented 7 years ago

Thanks for the kind remarks about the work and paper! I think there's an enormous potential here. One especially nice application not in the paper is SMT solving, writing predicates/constraints simply as a function to Bool in regular Haskell.

Yes to targeting other programming languages. I'm now generating GLSL and Verilog. I think C, Javascript, and Swift would be fairly easy as well. Another project I've started on is reproducing Pan, Vertigo, and Eros via compiling-to-categories. Will combine categories for GPU code generation, GUIs, and differentiable functions (for lighting).

jwiegley commented 7 years ago

@chriseidhof I'm also working, both in Haskell and outside of Haskell, at applying Conal's ideas to other languages as well. As Conal says, there is tremendous potential here. For example, I think it offers a much better answer to the "expression problem" one encounters when attempting to translate between domains using deeply embedded DSLs.

chriseidhof commented 7 years ago

@jwiegley awesome. Thanks for ledger btw, heavy user.

I've been wondering if it would be interesting to have a language that's designed just for this. Basically, a high-level language that compiles down to a simple core, not for optimizations, but for further backends. It would be useful to have function names (etc.) as well. Backends could enable specific optimizations, etc.

jwiegley commented 7 years ago

@chriseidhof You've almost just summarized what concat actually does, so can you clarify what your proposal would add a bit more?