Using GHC API to compile Haskell sources to CORE and CORE to binary

Hello All! :) Recently I've came across a problem and hopefully you could help me with it. Basically I and some people here are running a startup and we have created a language for processing images. This language has 2 interchangeable representations - textual and visual, dataflow one. Right now we are compiling it to haskell sources, but we want to move over GHC CORE. Getting into GHC has a high learning curve, as far as we see, and we would be very thankfull for any help with a minimal working example of compiling haskell sources to CORE and then CORE to binaries. I've posted couple days ago a detailed question on StackOverflow, here: http://stackoverflow.com/questions/28059669/using-ghc-api-to-compile-haskell... I would be very thankful for any help or hints! All the best, Wojciech

There used to be an external representation of core intended to be
used for such things. It was recently removed because it had gotten
stale and no one wanted to take responsibility for maintaining it. So
at the moment, Core is really just an AST, not a proper language, and
you'll have to hack GHC if you want to inject it.
On Tue, Jan 27, 2015 at 6:10 PM, Wojciech Danilo
Hello All! :) Recently I've came across a problem and hopefully you could help me with it. Basically I and some people here are running a startup and we have created a language for processing images. This language has 2 interchangeable representations - textual and visual, dataflow one.
Right now we are compiling it to haskell sources, but we want to move over GHC CORE. Getting into GHC has a high learning curve, as far as we see, and we would be very thankfull for any help with a minimal working example of compiling haskell sources to CORE and then CORE to binaries. I've posted couple days ago a detailed question on StackOverflow, here:
http://stackoverflow.com/questions/28059669/using-ghc-api-to-compile-haskell...
I would be very thankful for any help or hints! All the best, Wojciech
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Hello David, thank you for your response! :)
I've got few questions regarding it:
1) Does it mean there are no datatypes dedicated to "a core language" ?
2) All passes are transforming AST -> AST? If so, what does the function
`compileToCoreModule` does?
3) Additional - is there any subset of the AST that we can call "CORE" ?
4) Do all the documentation (like this one:
https://ghc.haskell.org/trac/ghc/wiki/Commentary/Compiler/CoreSynType)
should be considered obsolete?
All the best,
Wojciech
Wed Jan 28 2015 at 3:55:12 AM użytkownik David Feuer
There used to be an external representation of core intended to be used for such things. It was recently removed because it had gotten stale and no one wanted to take responsibility for maintaining it. So at the moment, Core is really just an AST, not a proper language, and you'll have to hack GHC if you want to inject it.
On Tue, Jan 27, 2015 at 6:10 PM, Wojciech Danilo
wrote: Hello All! :) Recently I've came across a problem and hopefully you could help me with it. Basically I and some people here are running a startup and we have created a language for processing images. This language has 2 interchangeable representations - textual and visual, dataflow one.
Right now we are compiling it to haskell sources, but we want to move over GHC CORE. Getting into GHC has a high learning curve, as far as we see, and we would be very thankfull for any help with a minimal working example of compiling haskell sources to CORE and then CORE to binaries. I've posted couple days ago a detailed question on StackOverflow, here:
http://stackoverflow.com/questions/28059669/using-ghc- api-to-compile-haskell-sources-to-core-and-core-to-binary
I would be very thankful for any help or hints! All the best, Wojciech
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

I can't answer all those questions, but I believe CoreSynType is the
AST representing Core.
On Tue, Jan 27, 2015 at 10:12 PM, Wojciech Danilo
Hello David, thank you for your response! :) I've got few questions regarding it: 1) Does it mean there are no datatypes dedicated to "a core language" ? 2) All passes are transforming AST -> AST? If so, what does the function `compileToCoreModule` does? 3) Additional - is there any subset of the AST that we can call "CORE" ? 4) Do all the documentation (like this one: https://ghc.haskell.org/trac/ghc/wiki/Commentary/Compiler/CoreSynType) should be considered obsolete?
All the best, Wojciech
Wed Jan 28 2015 at 3:55:12 AM użytkownik David Feuer
napisał: There used to be an external representation of core intended to be used for such things. It was recently removed because it had gotten stale and no one wanted to take responsibility for maintaining it. So at the moment, Core is really just an AST, not a proper language, and you'll have to hack GHC if you want to inject it.
On Tue, Jan 27, 2015 at 6:10 PM, Wojciech Danilo
wrote: Hello All! :) Recently I've came across a problem and hopefully you could help me with it. Basically I and some people here are running a startup and we have created a language for processing images. This language has 2 interchangeable representations - textual and visual, dataflow one.
Right now we are compiling it to haskell sources, but we want to move over GHC CORE. Getting into GHC has a high learning curve, as far as we see, and we would be very thankfull for any help with a minimal working example of compiling haskell sources to CORE and then CORE to binaries. I've posted couple days ago a detailed question on StackOverflow, here:
http://stackoverflow.com/questions/28059669/using-ghc-api-to-compile-haskell...
I would be very thankful for any help or hints! All the best, Wojciech
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Ok, so things are not in such poor condition than I imagined after your
first reply. Anyway I would be very thankful if anybody here would help me
with a minimal example which compiles haskell sources to CoreSynType (or
whatever core is encoded in) and then into binary - so I can inspect ghow
core is generated and replace in the future by mu custom one :)
Wed Jan 28 2015 at 4:53:01 AM użytkownik David Feuer
I can't answer all those questions, but I believe CoreSynType is the AST representing Core.
Hello David, thank you for your response! :) I've got few questions regarding it: 1) Does it mean there are no datatypes dedicated to "a core language" ? 2) All passes are transforming AST -> AST? If so, what does the function `compileToCoreModule` does? 3) Additional - is there any subset of the AST that we can call "CORE" ? 4) Do all the documentation (like this one: https://ghc.haskell.org/trac/ghc/wiki/Commentary/Compiler/CoreSynType) should be considered obsolete?
All the best, Wojciech
Wed Jan 28 2015 at 3:55:12 AM użytkownik David Feuer < david.feuer@gmail.com> napisał:
There used to be an external representation of core intended to be used for such things. It was recently removed because it had gotten stale and no one wanted to take responsibility for maintaining it. So at the moment, Core is really just an AST, not a proper language, and you'll have to hack GHC if you want to inject it.
On Tue, Jan 27, 2015 at 6:10 PM, Wojciech Danilo
wrote: Hello All! :) Recently I've came across a problem and hopefully you could help me with it. Basically I and some people here are running a startup and we have created a language for processing images. This language has 2 interchangeable representations - textual and visual, dataflow one.
Right now we are compiling it to haskell sources, but we want to move over GHC CORE. Getting into GHC has a high learning curve, as far as we see, and we would be very thankfull for any help with a minimal working example of compiling haskell sources to CORE and then CORE to binaries. I've
On Tue, Jan 27, 2015 at 10:12 PM, Wojciech Danilo
wrote: posted couple days ago a detailed question on StackOverflow, here:
http://stackoverflow.com/questions/28059669/using-ghc- api-to-compile-haskell-sources-to-core-and-core-to-binary
I would be very thankful for any help or hints! All the best, Wojciech
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Wed, Jan 28, 2015 at 04:06:07AM +0000, Wojciech Danilo wrote:
Ok, so things are not in such poor condition than I imagined after your first reply. Anyway I would be very thankful if anybody here would help me with a minimal example which compiles haskell sources to CoreSynType (or whatever core is encoded in) and then into binary - so I can inspect ghow core is generated and replace in the future by mu custom one :)
I'm certainly no expert, but I remembered that the Haste compiler compiles Haskell via Core to STG, so this may give you a start: https://github.com/valderman/haste-compiler/blob/master/src/Main.hs#L181 Tom

I have plenty of experience with GHC Core, but none with the GHC API. I'll explain what I know.
GHC's Core language is alive and very well. It's described in many academic papers -- "Giving Haskell a Promotion" and "Safe Zero-Cost Coercions for Haskell" both contain nice descriptions of a theoretical version of the language. The actual language as implemented is described in https://github.com/ghc/ghc/blob/master/docs/core-spec/core-spec.pdf?raw=true though that is quite terse.
Expressions in Core are stored in the CoreExpr type, types are the Type type, and coercions are the Coercion type. The file coreSyn/CoreLint.hs performs typechecking over this language.
A desugared module is written in Core. If you know how to manipulate the GHC API into producing a desugared module (a ModGuts, I believe), you have a Core program. Alternatively, you can create your own ModGuts somehow, and then perhaps convince the GHC API to carry on with it.
Core is used for all of GHC's internal manipulations: simplifying & optimization. The fact that it's typechecked is a critical sanity check on GHC itself -- we want to know if a transformation changes any types! (They shouldn't.)
External Core, on the other hand, was a project that lived for some time, allowing a command-line interface for injecting Core into GHC, without even the GHC API. It had a printer and a parser. However, it bitrotted over the years and was recently removed, as the rot showed that no one was actually using it. However, if you are using the GHC API, I don't think that the lack of External Core should be an issue. I believe External Core's salient feature was its parser, and you don't need that as an API user.
I hope this is helpful!
Richard
On Jan 27, 2015, at 6:10 PM, Wojciech Danilo
Hello All! :) Recently I've came across a problem and hopefully you could help me with it. Basically I and some people here are running a startup and we have created a language for processing images. This language has 2 interchangeable representations - textual and visual, dataflow one.
Right now we are compiling it to haskell sources, but we want to move over GHC CORE. Getting into GHC has a high learning curve, as far as we see, and we would be very thankfull for any help with a minimal working example of compiling haskell sources to CORE and then CORE to binaries. I've posted couple days ago a detailed question on StackOverflow, here:
http://stackoverflow.com/questions/28059669/using-ghc-api-to-compile-haskell...
I would be very thankful for any help or hints! All the best, Wojciech _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (4)
-
David Feuer
-
Richard Eisenberg
-
Tom Ellis
-
Wojciech Danilo