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

TH doesn't allow generating CTYPE pragma #124

Open
phadej opened this issue Aug 30, 2024 · 5 comments
Open

TH doesn't allow generating CTYPE pragma #124

phadej opened this issue Aug 30, 2024 · 5 comments

Comments

@phadej
Copy link
Collaborator

phadej commented Aug 30, 2024

There are simply no entry for that in AST:

Prelude Language.Haskell.TH> [d| newtype {-# CTYPE "int" #-} Bar = Bar Int |] >>= print
[NewtypeD [] Bar_0 [] Nothing (NormalC Bar_1 [(Bang NoSourceUnpackedness NoSourceStrictness,ConT GHC.Types.Int)]) []]

I feel that is a show stopper.

FWIW, it's not possible with haskell-src-exts either.

@phadej
Copy link
Collaborator Author

phadej commented Aug 30, 2024

I opened upstream issue https://gitlab.haskell.org/ghc/ghc/-/issues/25223, but we have to figure out what to do in the meantime. (I guess we simply wont' use CApiFFI for quite a while).

@edsko
Copy link
Collaborator

edsko commented Sep 3, 2024

Given both this problem as well as your reluctance to use haskell-src-exts (#123), perhaps we should have our own abstraction for Haskell code after all (@FinleyMcIlwaine had one in his prototype implementation, but we decided in the end that it wasn't worth it). It should then be easy to generate both Haskell source as well as TH splices from this, although I guess if TH doesn't support this, the tool in TH mode would not be quite fully functional, which is unfortunate but perhaps unavoidable then?

@phadej
Copy link
Collaborator Author

phadej commented Sep 3, 2024

perhaps we should have our own abstraction for Haskell code after all

I have thought about this, and I think it's worth it. We'd include only features we truly need. haskell-src-meta goes from "anything possible to TH", which is a lot to do, and they even say

The translation from haskell-src-exts abstract syntax to template-haskell abstract syntax isn't 100% complete yet.

Until we start working on high-level API generation, we don't even generate a lot of syntax. Not that high-level API would need all the GHC Haskell whistles either.

@edsko
Copy link
Collaborator

edsko commented Sep 3, 2024

Ok, then let's do that and introduce our own Haskell abstraction.

@edsko edsko added this to the 1: `Storable` instances milestone Sep 4, 2024
@edsko
Copy link
Collaborator

edsko commented Sep 6, 2024

One advantage of our own representation is that we can be more typed; rather than just specifying "class instance", we can say "this is a storable instance", and provide exactly what we need: the AST would be more typed. I'll start on this now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants