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

GHC's strictness analysis can be confusing in combination with black boxes #2728

Open
martijnbastiaan opened this issue May 28, 2024 · 1 comment

Comments

@martijnbastiaan
Copy link
Member

Say I've got a black box:

prim :: (A, B, C)
prim = (undefined, undefined, undefined)
{-# OPAQUE prim #-}
{-# ANN prim hasBlackbox #-}

If this output is used:

let 
  (a, b, c) = prim
  d = register a b c

GHC might conclude that, because register is strict in some of its arguments, that the result of the calculation is undefined. This is undesirable, because it will turn perfectly synthesizable code into non-synthesizable junk.

If think we should:

  1. Enable -fno-strictness in starter projects
  2. Implement a check that makes sure that primitives don't have strictness information attached
  3. (After (2), remove (1))

Workaround:

{-# OPTIONS_GHC -fno-strictness #-}
@christiaanb
Copy link
Member

The warning won’t help you if the primitive is already elided from the use-site by GHC.

Perhaps we should improve our documentation with regards to these “no-simulation” primitives. Given that custom primitives are an advanced topic, I suspect people only discover them by reading the documentation, so that seems like the right spot to handle this. Turning off strictness analysis for all code in the starter project seems like a ‘baby with the bath water’ kind of thing.

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