Closed martijnbastiaan closed 1 year ago
Now that we're properly marking all primitives as OPAQUE, we could try re-enabling the worker/wrapper transform on clash-prelude when compiling with GHC >= 9.4.
This PR has been scripted for 99%. Here are the steps:
^\{-# NOINLINE (.*) #-\}
, replace with -- See: https://github.com/clash-lang/clash-compiler/pull/2511\n{-# CLASH_OPAQUE $1 #-}
in clash-prelude,clash-cores,benchmark,tests/shouldwork,tests/shouldfail,examples
.need_cpp
using git status --short | grep -E '^ M ' | grep -E '.hs$' | sed 's/^ M //g' > need_cpp
CPP
pragmas everywhere by running 🍝 python3 cppaghetti.py
🍝.
In order for Clash to work properly, some names need to remain untouched by GHC's compilation process. Examples of these names include top entities annotated with a
Synthesize
pragma, or functions having an associated black box implementation. For the longest time, we have tried to instruct GHC to do so by marking functions as "no inline":While this does work in the majority of cases, GHC will still touch the name of this function in some, making Clash fail to recognize it. Hence, GHC 9.4 introduce a new pragma
OPAQUE
:This PR introduces a change making Clash warn against usage of
NOINLINE
on GHCs 9.4 and newer. To remain compatible with older GHCs, Clash's code base itself defines a CPP macro that definesCLASH_OPAQUE
as eitherNOINLINE
orOPAQUE
depending on the version of GHC the code base is compiled with. This means that you'll find the following pattern across it:This macro is local to Clash itself, and is not reusable within other projects. If your project suffers from similar cross-compatibility problems, consider using a similar strategy.
Warn against non-opaque primitive functions on GHC >= 9.4.
Fixes #2510
Still TODO:
Write a changelog entry (see changelog/README.md)9.4 / 9.6 support is not in a Hackage release yetOPAQUE
with CPP :cry:. Note that we also want to mark top entities asOPAQUE
as GHC can touch them too in some circumstances.