clash-lang / stack-templates

Templates for `stack new` command
Creative Commons Zero v1.0 Universal
3 stars 1 forks source link

Enable FlexibleContexts by default? #27

Closed lmbollen closed 9 months ago

lmbollen commented 1 year ago

When creating for example a small counter:

counter = register 0 ( counter + 1)

counter already requires a domain to be sampled. If you´d want to make this a counter for System. You can´t make the type simply Signal System (Unsigned 8) because register requires HiddenClockResetEnable dom.

For System, you now have to explicitly supply HiddenClockResetEnable System, which you can't because FlexibleContexts is not enabled by default. Now the user must also figure out what LANGUAGE pragmas are and how to set FlexibleContexts.

I think all these steps introduce a lot of friction and our template projects should maybe show how to deal with more of these situations.

DigitalBrains1 commented 1 year ago

I think it's a bug if the starter project doesn't enable by default the extensions that we enable by default for compiling with clash. If I understand correctly, that would mean using clash directly accepts more or different stuff than using a starter project, which if anything is the reverse of what we want.

Also, I'm working on a PR where for use inside clash-compiler, we enable all extensions that are GHC2021 blessed. I think it would also be okay to enable them all by default for Clash designs as well.

Note your example is slightly flawed in that instead of HiddenClockResetEnable System you can actually write SystemClockResetEnable ;-). But if you replace all occurences of System by XilinxSystem then your point stands. Or any other domain for that matter.

lmbollen commented 10 months ago

I'm looking into the GHC2021 extensions, there are some we don't want such as StarIsType (we already have NoStarIsType enabled so that checks out) since using StarIsType breaks type level multiplication.

Furthermore using NamedWildCards causes errors in bittide without enabling PartialTypeSignatures. Specifically in combination with the circuit-notation plugin for circuits that are ignored.

I don't think just enabling the GHC2021 blessed extensions is a great idea and we should just see what encounter and selectively enable extensions based on that.

A quick search in bittide shows that we enable the following extensions commonly on a per module basis:

RecordWildCards
NamedFieldPuns
FlexibleContexts

(I'm personally guilty of introducing most of those) I'd prefer just adding those.

lmbollen commented 9 months ago

Solved by #33