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

Under-applied constructor when compiling with separate compilation #2634

Open
bgamari opened this issue Dec 30, 2023 · 3 comments
Open

Under-applied constructor when compiling with separate compilation #2634

bgamari opened this issue Dec 30, 2023 · 3 comments

Comments

@bgamari
Copy link
Contributor

bgamari commented Dec 30, 2023

With clash-ghc-1.8.0 and GHC 9.2.8, a simple entity using my axi-register package builds fine when built in conjunction with axi-register in a single compilation:

$ clash --vhdl Test.hs -isrc -XRecordWildCards -XUndecidableInstances
GHC: Setting up GHC took: 0.567s
GHC: Compiling and loading modules took: 3.945s
Clash: Parsing and compiling primitives took 0.160s
GHC+Clash: Loading modules cumulatively took 7.201s
Clash: Compiling CDAS.topEntity
Clash: Normalization took 0.002s
Clash: Netlist generation took 0.000s
Clash: Compiling CDAS.topEntity took 0.012s
Clash: Total compilation took 7.214s

However, if we use Cabal to build axi-register and then compile the same testcase using the unfoldings contained in the interface files we have the following error:

$ clash --vhdl Test.hs 
GHC: Setting up GHC took: 0.514s
GHC: Compiling and loading modules took: 1.324s
Clash: Parsing and compiling primitives took 0.138s
GHC+Clash: Loading modules cumulatively took 2.071s
Clash: Compiling CDAS.topEntity
Clash: Normalization took 0.010s

<no location info>: error:
    Clash error call:
    Clash.Netlist(1041): Under-applied constructor
    CallStack (from HasCallStack):
      error, called at src/Clash/Netlist.hs:1041:17 in clash-lib-1.8.0-K7LaVRc69b66OfA18pqV2I:Clash.Netlist
      mkDcApplication, called at src/Clash/Netlist.hs:863:16 in clash-lib-1.8.0-K7LaVRc69b66OfA18pqV2I:Clash.Netlist
      mkExpr, called at src/Clash/Netlist.hs:450:30 in clash-lib-1.8.0-K7LaVRc69b66OfA18pqV2I:Clash.Netlist
      mkDeclarations', called at src/Clash/Netlist.hs:409:18 in clash-lib-1.8.0-K7LaVRc69b66OfA18pqV2I:Clash.Netlist
      mkDeclarations, called at src/Clash/Netlist.hs:284:40 in clash-lib-1.8.0-K7LaVRc69b66OfA18pqV2I:Clash.Netlist
      genComponentT, called at src/Clash/Netlist.hs:247:41 in clash-lib-1.8.0-K7LaVRc69b66OfA18pqV2I:Clash.Netlist
      genComponent, called at src/Clash/Netlist.hs:125:9 in clash-lib-1.8.0-K7LaVRc69b66OfA18pqV2I:Clash.Netlist

This is very reminiscent of #2628

Reproducing

$ git clone https://git.smart-cactus.org/ben/axi-register
$ cd axi-register
$ git checkout repro
$ nix develop ".#develop"
# This will provide an environment with `clash-ghc`, `axi-register`, and its dependencies
$ clash --vhdl Test.hs   # this works
$ clash --vhdl Test.hs -isrc -XRecordWildCards -XUndecidableInstances # This will fail
@bgamari bgamari changed the title Separate compilation broken? Under-applied constructor when compiling with separate compilation Dec 30, 2023
@bgamari
Copy link
Contributor Author

bgamari commented Dec 30, 2023

I have minimized the issue quite significantly. The data constructor in question here appears to be Clash.Signal.Internal.(:-), which appears to be mentioned a few places in the "bad" case yet not at all in the "good". Given that :- isn't synthesizable, is it expected that it appear in programs compiled by Clash?

It appears that bundle in the example is being worker-wrapper'd. Perhaps this is the reason?

@bgamari
Copy link
Contributor Author

bgamari commented Dec 30, 2023

I can confirm that -fno-worker-worker avoids the issue. I have also seen that clash-cores disables worker-wrapper. Is this recommended practice? If so, it should probably be documented a bit more prominently.

@christiaanb
Copy link
Member

We do it for the starter project as well, though going by the comment for different reasons: https://github.com/clash-lang/stack-templates/blob/572614b9c34dd4b17f7eb209931e873f220b3a7f/projects/simple/%7B%7Bname%7D%7D.cabal#L56-L59

Also, when we compile from source we emit a warning when W/W is enabled globally: 957a302

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