New primitives requiring literal syntax

From the 9.12.1-alpha2 release notes:

New vector shuffle instructions, such as shuffleFloatX4# :: FloatX4# -> FloatX4# -> (# Int#, Int#, Int#, Int# #) -> FloatX4# . These instructions take two input vectors and a collection of indices (which must be compile-time literal integers)

I thought it is interesting that they are required to be literals. I suppose literals are required because they are guaranteed to be available at compile-time. However, there are other approaches to provide compile time computation:

  • TemplateSyntax, which I imagine the GHC team might want to avoid, given that it has been so hard to get it working with JavaScript and cross compilation?
  • Singletons, which I imagine can’t be used in boot libraries, as it is not considered elegant enough? With singletons, the function itself would be indexed by the unboxed tuple. I haven’t used singletons, so I am not sure whether this would work?

It’s interesting that GHC is improving support for type-level programming, but at the same time, ‘magic’ functions are able to verify whether its inputs are arguments. I use the term ‘magic’ because I imagine that only hardwired functions are able to do something like this. Is that true?

Primops are greatly restricted and can use only few, also primitive types. So anything like singletons is out of question at this level.

A higher-level library for vectorised operations could indeed use TH / singletons in its interface.

They have to be literals by the time they reach the code generator because they are lowered to X86’s SHUFPS which requires an immediate argument.

But as @Bodigrim writes, it’s possible to add higher-level safer interfaces on top of them.

1 Like