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

Strongly separate clash-protocols-base and clash-protocols #118

Merged
merged 6 commits into from
Oct 3, 2024

Conversation

lmbollen
Copy link
Member

clash-protocols-base should only contain code and definitions related to the circuit plugin. This includes the Circuit definition and Protocol typeclass. Furthermore we include instances for types imported from underlying clash libraries such as tuples, Vec and Signal.

@lmbollen lmbollen force-pushed the lucas/reorder-modules branch from f09f91b to 5ddd411 Compare September 27, 2024 12:23
@t-wallet
Copy link
Collaborator

Unused import in Protocols.Wishbone. Other than that, LGTM.

It would be nice if we could completely hide the clash-protocols-base package from the outside as well, and just re-export everything via clash-protocols. Currently, users have to specify both clash-protocols and clash-protocols-base in their package sources.

@DigitalBrains1
Copy link
Member

DigitalBrains1 commented Sep 27, 2024

Currently, users have to specify both clash-protocols and clash-protocols-base in their package sources.

Why is that? Doesn't the

  reexported-modules:
    Protocols.Plugin

in clash-protocols.cabal mean they only have to specify a dependency on clash-protocols in their Cabal file and get everything they need including the plugin?

@lmbollen lmbollen force-pushed the lucas/reorder-modules branch 2 times, most recently from f082174 to db1274d Compare September 30, 2024 11:45
@lmbollen lmbollen marked this pull request as ready for review September 30, 2024 11:45
@lmbollen lmbollen force-pushed the lucas/reorder-modules branch from db1274d to 2bda9fb Compare October 2, 2024 08:53
@lmbollen
Copy link
Member Author

lmbollen commented Oct 2, 2024

Currently, users have to specify both clash-protocols and clash-protocols-base in their package sources.

Why is that? Doesn't the

  reexported-modules:
    Protocols.Plugin

in clash-protocols.cabal mean they only have to specify a dependency on clash-protocols in their Cabal file and get everything they need including the plugin?

I think if you build the package from github using e.g.:

source-repository-package
  type: git
  location: https://github.com/clash-lang/clash-protocols.git
  tag: 623ecd9658fa5b15f71b0d86bac6b714b4b86dc4

You also need to add the dependency for clash-protocols-base

@DigitalBrains1
Copy link
Member

Right, I had misunderstood the comment.

Copy link
Member

@DigitalBrains1 DigitalBrains1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This are no longer needed:
clash-protocols-base/src/Protocols/Plugin.hs:

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms #-}

This can now be guarded again:
clash-protocols/src/Protocols/Internal.hs:

#if !MIN_VERSION_clash_prelude(1, 8, 2)
{-# OPTIONS_GHC -fno-warn-orphans #-}
#endif

And I'd like to suggest to export everything from Protocols.Plugin{,.Units,.TaggedBundle} from Protocols.Internal. This makes things easier and less surprising.

I did turn that suggestion into individual per-file suggestions, but if you want, I can add a fixup commit that does this, since I already wrote it to test it. Saves you the work of recreating it.

Also, I only commented on documentation things if I thought they were easy to miss. All obvious "polishing the docs" stuff goes without comment, we can do it later.

Comment on lines +50 to +52
{- | __NB__: The documentation only shows instances up to /3/-tuples. By
default, instances up to and including /12/-tuples will exist. If the flag
@large-tuples@ is set instances up to the GHC imposed limit will exist. The
GHC imposed limit is either 62 or 64 depending on the GHC version.
-}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is slightly misleading. People will encounter this documentation in clash-protocols. So they might set the -flarge-tuples flag on clash-protocols when really they should set it on both clash-protocols-base as well as clash-protocols.

However, I now see it's actually worse than that. The instances defined in clash-protocols-base are not documented at all in the Haddock for clash-protocols. I think this is a real shortcoming. People will not easily be able to know that these instances exist at all.

clash-protocols-base/src/Protocols/Plugin/Internal.hs Outdated Show resolved Hide resolved
import Protocols.Internal
import Protocols.Internal.TH (idleCircuitTupleInstances)
import Protocols.Plugin
import Protocols.Plugin.Cpp (maxTupleSize)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you can see in the generated Haddock, this does not work. maxTupleSize is supposed to be 3 when generating Haddock. But when generating Haddock for clash-protocols, clash-protocols-base is compiled without -DHADDOCK_ONLY and so maxTupleSize is 12.

This package will need its own copy of Cpp.hs. That will also solve that clash-protocols will once again honour its own -flarge-tuples flag instead of the one on clash-protocols-base.

clash-protocols/src/Protocols.hs Outdated Show resolved Hide resolved
clash-protocols/src/Protocols.hs Outdated Show resolved Hide resolved
clash-protocols/src/Protocols/Internal.hs Show resolved Hide resolved
clash-protocols/src/Protocols/Internal.hs Show resolved Hide resolved
clash-protocols/src/Protocols/Internal/TH.hs Outdated Show resolved Hide resolved
clash-protocols/src/Protocols/Axi4/ReadAddress.hs Outdated Show resolved Hide resolved
lmbollen and others added 6 commits October 3, 2024 16:24
`clash-protocols-base` should only contain code and definitions related to the circuit plugin.
This includes the `Circuit` definition and `Protocol` typeclass. Furthermore we include instances
for types imported from underlying clash libraries such as tuples, `Vec` and `Signal`.
It not only contains classes, but also types
The separation between plugin related code and protocol related code
should be obvious from the module hierarchy
@DigitalBrains1
Copy link
Member

I've converted the remaining review feedback to issues: #119 #120

@DigitalBrains1 DigitalBrains1 merged commit d3fc7f4 into main Oct 3, 2024
8 checks passed
@DigitalBrains1 DigitalBrains1 deleted the lucas/reorder-modules branch October 3, 2024 15:59
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

Successfully merging this pull request may close these issues.

3 participants