Simplify KnownDomain#3163
Conversation
|
Looking at the failing tests, it seems the existing encoding is ingrained in the Clash compiler to figure out things about domain configurations during HDL generation:
|
|
I would like to do this. In the past I tried something like this as well but I never got it working without breaking type inference on existing code. If you want @kleinreact I can take up this PR and see if I can get it to pass all existing tests. |
|
Thanks for the offer @rowanG077. I am currently evaluating some more improvements that should be applicable here, where I'd prefer to ship them all in a single PR in the end, as this is a quite sensible part of the prelude. I hope to be able to finish my evaluation soon. |
425a142 to
ed077ab
Compare
You can find the results of my evaluation for further discussion in #3178. |
It was irritating me that
KnownDomaininstances have to define all that redundant boilerplate. Hence, after a small investigation I ended up with the following simplifications implemented by this PR.The changes basically are a drop-in replacement, except that the associations with the
KnownDomainclass have slightly changed (only affecting imports of internal modules).;The most important changes are:
knownDomainis not part of theKnownDomainclass anymore, which makes it impossible for users to give a wrong implementation for this function. Note that users could have definedknownDomain = undefinedin custom instances before.KnownConfis not part of theKnownDomainany more, which removes the need for type family applications when access to the fields ofKnownDomain domis required.This especially can lead to problems when only access to some particular fields is needed in a constraint signature. With the old definition, GHC simply cannot expect
KnownConf domto be defined as some'DomainConfiguration a b c d e fby the user potentially leading to type errors. With the update of this PR,KnownConf dominstead is defined to beremoving any ambiguity for GHC.
The
period,activeEdge,resetKind,initBehavior, andresetPolarityfields are now protected via additionalKnown...classes. Note that users could have defined something likein custom instances before, which now is not possible any more.
The updates simplifies
KnownDomaininstances now really only needing the relevant values, e.g.,As a secondary step, we now technically also could get rid of all the singleton definitions, like
SDomainConfiguration,SActiveEdge, etc., just by lettingknownDomaindirectly return aVDomainConfiguration. However, I would keep such an update to be shipped with a separate PR at first.Still TODO: