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

More stringy names in Clash.GHC.Evaluator.Primitive #2795

Open
bgamari opened this issue Aug 22, 2024 · 2 comments
Open

More stringy names in Clash.GHC.Evaluator.Primitive #2795

bgamari opened this issue Aug 22, 2024 · 2 comments

Comments

@bgamari
Copy link
Contributor

bgamari commented Aug 22, 2024

Hard-coded stringy names are problematic, especially in GHC 9.10.1 due to the ghc-internal rewrite. Some occurrences were handled in e565d26, but there are quite a few more in Clash.GHC.Evaluator.Primitive (c.f. GHC.Float.integerToFloat# and many more).

@bgamari
Copy link
Contributor Author

bgamari commented Aug 22, 2024

There also appear to be many more such cases in the blackboxes in clash-lib/prims/common.

@DigitalBrains1
Copy link
Member

Maybe we can replace the YAML files in clash-lib/prims with something like

import GHC.Classes (gtInt, geInt, ltInt, leInt)

let
  gtIntName = 'gtInt
  geIntName = 'geInt
  ltIntName = 'ltInt
  leIntName = 'leInt
in InlineYamlPrimitive [minBound..] [__i|
     - BlackBox:
         name: #{gtIntName}
         kind: Expression
         type: 'gtInt :: Int ->
           Int -> Bool'
         template: ~ARG[0] > ~ARG[1]
     - BlackBox:
         name: #{geIntName}
         kind: Expression
         type: 'geInt :: Int ->
           Int -> Bool'
         template: ~ARG[0] >= ~ARG[1]
     - BlackBox:
         name: #{ltIntName}
         kind: Expression
         type: 'ltInt :: Int ->
           Int -> Bool'
         template: ~ARG[0] < ~ARG[1]
     - BlackBox:
         name: #{leIntName}
         kind: Expression
         type: 'leInt :: Int ->
           Int -> Bool'
         template: ~ARG[0] <= ~ARG[1]
     |])

somewhere as part of clash-lib Haskell files. This a sketch, first of all I don't know if InlineYamlPrimitive accepts a list of BlackBox and secondly it's still not tied in anywhere anyway, but as a general idea.

Also, we might define an ADT somewhat like

data BlackBox =
  { name :: Language.Haskell.TH.Syntax.Name
  , kind :: ...
  , type :: Text
  , template :: Text
  }

where we can immediately pass a Name. I think this would be a nice way to define primitives in user designs as well, but it might be significantly more effort (not my area of expertise, that part of the code).

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