From 40ea83e76dce4ab91c714e0a6ee1718bca3ced88 Mon Sep 17 00:00:00 2001 From: Pingu Date: Sat, 20 May 2023 17:22:43 +0200 Subject: [PATCH] Making sure that it builds is annoying --- CHANGELOG.md | 5 - PPU.cabal | 230 ++++++++++++++++----------------- app/Clash.hs | 6 + app/Clashi.hs | 6 + app/Main.hs | 8 -- cabal.project | 13 ++ src/Example/Project.hs | 19 +++ src/MyLib.hs | 4 - stack.yaml | 7 + stack.yaml.lock | 40 ++++++ test/Main.hs | 4 - tests/Tests/Example/Project.hs | 26 ++++ tests/doctests.hs | 8 ++ tests/unittests.hs | 10 ++ 14 files changed, 250 insertions(+), 136 deletions(-) delete mode 100644 CHANGELOG.md create mode 100644 app/Clash.hs create mode 100644 app/Clashi.hs delete mode 100644 app/Main.hs create mode 100644 cabal.project create mode 100644 src/Example/Project.hs delete mode 100644 src/MyLib.hs create mode 100644 stack.yaml create mode 100644 stack.yaml.lock delete mode 100644 test/Main.hs create mode 100644 tests/Tests/Example/Project.hs create mode 100644 tests/doctests.hs create mode 100644 tests/unittests.hs diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 371bd47..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,5 +0,0 @@ -# Revision history for PPU - -## 0.1.0.0 -- YYYY-mm-dd - -* First version. Released on an unsuspecting world. diff --git a/PPU.cabal b/PPU.cabal index 934f66a..393ebb6 100644 --- a/PPU.cabal +++ b/PPU.cabal @@ -1,130 +1,130 @@ -cabal-version: 3.4 --- The cabal-version field refers to the version of the .cabal specification, --- and can be different from the cabal-install (the tool) version and the --- Cabal (the library) version you are using. As such, the Cabal (the library) --- version used must be equal or greater than the version stated in this field. --- Starting from the specification version 2.2, the cabal-version field must be --- the first thing in the cabal file. +cabal-version: 3.4 +name: PPU +version: 1.0 +license: MIT +author: Nor Führ +maintainer: Nor Führ --- Initial package description 'PPU' generated by --- 'cabal init'. For further documentation, see: --- http://haskell.org/cabal/users-guide/ --- --- The name of the package. -name: PPU +common common-options + default-extensions: + BangPatterns + BinaryLiterals + ConstraintKinds + DataKinds + DefaultSignatures + DeriveAnyClass + DeriveDataTypeable + DeriveFoldable + DeriveFunctor + DeriveGeneric + DeriveLift + DeriveTraversable + DerivingStrategies + InstanceSigs + KindSignatures + LambdaCase + NoStarIsType + PolyKinds + RankNTypes + ScopedTypeVariables + StandaloneDeriving + TupleSections + TypeApplications + TypeFamilies + TypeOperators + ViewPatterns --- The package version. --- See the Haskell package versioning policy (PVP) for standards --- guiding when and how versions should be incremented. --- https://pvp.haskell.org --- PVP summary: +-+------- breaking API changes --- | | +----- non-breaking API additions --- | | | +--- code changes with no API change -version: 0.1.0.0 + -- TemplateHaskell is used to support convenience functions such as + -- 'listToVecTH' and 'bLit'. + TemplateHaskell + QuasiQuotes --- A short (one-line) description of the package. -synopsis: Pingu Processing Unit + -- Prelude isn't imported by default as Clash offers Clash.Prelude + NoImplicitPrelude + ghc-options: + -Wall -Wcompat + -haddock --- A longer description of the package. --- description: + -- Plugins to support type-level constraint solving on naturals + -fplugin GHC.TypeLits.Extra.Solver + -fplugin GHC.TypeLits.Normalise + -fplugin GHC.TypeLits.KnownNat.Solver --- URL for the project homepage or repository. -homepage: https://git.acorneroftheweb.com/pingu/ppu + -- Clash needs access to the source code in compiled modules + -fexpose-all-unfoldings --- The license under which the package is released. -license: MIT + -- Worker wrappers introduce unstable names for functions that might have + -- blackboxes attached for them. You can disable this, but be sure to add + -- a no-specialize pragma to every function with a blackbox. + -fno-worker-wrapper --- The file containing the license text. -license-file: LICENSE + -- Strict annotations - while sometimes preventing space leaks - trigger + -- optimizations Clash can't deal with. See: + -- + -- https://github.com/clash-lang/clash-compiler/issues/2361 + -- + -- These flags disables these optimizations. Note that the fields will + -- remain strict. + -fno-unbox-small-strict-fields + -fno-unbox-strict-fields + build-depends: + base, + Cabal, --- The package author(s). -author: Nor Führ + -- clash-prelude will set suitable version bounds for the plugins + clash-prelude >= 1.6.4 && < 1.8, + ghc-typelits-natnormalise, + ghc-typelits-extra, + ghc-typelits-knownnat, --- An email address to which users can send suggestions, bug reports, and patches. -maintainer: nor@acorneroftheweb.com - --- A copyright notice. --- copyright: -build-type: Simple - --- Extra doc files to be distributed with the package, such as a CHANGELOG or a README. -extra-doc-files: CHANGELOG.md - --- Extra source files to be distributed with the package, such as examples, or a tutorial module. --- extra-source-files: - -common warnings - ghc-options: -Wall library - -- Import common warning flags. - import: warnings + import: common-options + hs-source-dirs: src + exposed-modules: + Example.Project + default-language: Haskell2010 - -- Modules exported by the library. - exposed-modules: MyLib +-- Builds the executable 'clash', with PPU project in scope +executable clash + main-is: app/Clash.hs + default-language: Haskell2010 + Build-Depends: base, clash-ghc, PPU + if !os(Windows) + ghc-options: -dynamic - -- Modules included in this library but not exported. - -- other-modules: +-- Builds the executable 'clashi', with PPU project in scope +executable clashi + main-is: app/Clashi.hs + default-language: Haskell2010 + if !os(Windows) + ghc-options: -dynamic + build-depends: base, clash-ghc, PPU - -- LANGUAGE extensions used by modules in this package. - -- other-extensions: +test-suite doctests + type: exitcode-stdio-1.0 + default-language: Haskell2010 + main-is: doctests.hs + ghc-options: -Wall -Wcompat -threaded + hs-source-dirs: tests + build-depends: + base, + PPU, + doctest-parallel >= 0.2 && < 0.4, - -- Other library packages from which modules are imported. - build-depends: base ^>=4.17.0.0 - - -- Directories containing source files. - hs-source-dirs: src - - -- Base language which the package is written in. - default-language: GHC2021 - -executable PPU - -- Import common warning flags. - import: warnings - - -- .hs or .lhs file containing the Main module. - main-is: Main.hs - - -- Modules included in this executable, other than Main. - -- other-modules: - - -- LANGUAGE extensions used by modules in this package. - -- other-extensions: - - -- Other library packages from which modules are imported. - build-depends: - base ^>=4.17.0.0, - PPU - - -- Directories containing source files. - hs-source-dirs: app - - -- Base language which the package is written in. - default-language: GHC2021 - -test-suite PPU-test - -- Import common warning flags. - import: warnings - - -- Base language which the package is written in. - default-language: GHC2021 - - -- Modules included in this executable, other than Main. - -- other-modules: - - -- LANGUAGE extensions used by modules in this package. - -- other-extensions: - - -- The interface type and version of the test suite. - type: exitcode-stdio-1.0 - - -- Directories containing source files. - hs-source-dirs: test - - -- The entrypoint to the test suite. - main-is: Main.hs - - -- Test dependencies. - build-depends: - base ^>=4.17.0.0, - PPU +test-suite test-library + import: common-options + default-language: Haskell2010 + hs-source-dirs: tests + type: exitcode-stdio-1.0 + ghc-options: -threaded + main-is: unittests.hs + other-modules: + Tests.Example.Project + build-depends: + PPU, + QuickCheck, + hedgehog, + tasty >= 1.2 && < 1.5, + tasty-hedgehog, + tasty-th diff --git a/app/Clash.hs b/app/Clash.hs new file mode 100644 index 0000000..370a54a --- /dev/null +++ b/app/Clash.hs @@ -0,0 +1,6 @@ +import Clash.Main (defaultMain) +import Prelude +import System.Environment (getArgs) + +main :: IO () +main = getArgs >>= defaultMain diff --git a/app/Clashi.hs b/app/Clashi.hs new file mode 100644 index 0000000..185512a --- /dev/null +++ b/app/Clashi.hs @@ -0,0 +1,6 @@ +import Clash.Main (defaultMain) +import Prelude +import System.Environment (getArgs) + +main :: IO () +main = getArgs >>= defaultMain . ("--interactive":) diff --git a/app/Main.hs b/app/Main.hs deleted file mode 100644 index 60d904e..0000000 --- a/app/Main.hs +++ /dev/null @@ -1,8 +0,0 @@ -module Main where - -import qualified MyLib (someFunc) - -main :: IO () -main = do - putStrLn "Hello, Haskell!" - MyLib.someFunc diff --git a/cabal.project b/cabal.project new file mode 100644 index 0000000..2418753 --- /dev/null +++ b/cabal.project @@ -0,0 +1,13 @@ +packages: + PPU.cabal + +write-ghc-environment-files: always + +-- Eliminates the need for `--enable-tests`, which is needed for HLS. +tests: true + +-- Works around: https://github.com/recursion-schemes/recursion-schemes/issues/128. This +-- shouldn't harm (runtime) performance of Clash, as we only use recursion-schemes with +-- TemplateHaskell. +package recursion-schemes + optimization: 0 diff --git a/src/Example/Project.hs b/src/Example/Project.hs new file mode 100644 index 0000000..6b67e59 --- /dev/null +++ b/src/Example/Project.hs @@ -0,0 +1,19 @@ +module Example.Project (topEntity, plus) where + +import Clash.Prelude + +-- | Add two numbers. Example: +-- +-- >>> plus 3 5 +-- 8 +plus :: Signed 8 -> Signed 8 -> Signed 8 +plus a b = a + b + +-- | 'topEntity' is Clash's equivalent of 'main' in other programming +-- languages. Clash will look for it when compiling 'Example.Project' +-- and translate it to HDL. While polymorphism can be used freely in +-- Clash projects, a 'topEntity' must be monomorphic and must use non- +-- recursive types. Or, to put it hand-wavily, a 'topEntity' must be +-- translatable to a static number of wires. +topEntity :: Signed 8 -> Signed 8 -> Signed 8 +topEntity = plus diff --git a/src/MyLib.hs b/src/MyLib.hs deleted file mode 100644 index e657c44..0000000 --- a/src/MyLib.hs +++ /dev/null @@ -1,4 +0,0 @@ -module MyLib (someFunc) where - -someFunc :: IO () -someFunc = putStrLn "someFunc" diff --git a/stack.yaml b/stack.yaml new file mode 100644 index 0000000..8f6b155 --- /dev/null +++ b/stack.yaml @@ -0,0 +1,7 @@ +resolver: lts-19.33 + +extra-deps: + - clash-ghc-1.6.4 + - clash-prelude-1.6.4 + - clash-lib-1.6.4 + - concurrent-supply-0.1.8 diff --git a/stack.yaml.lock b/stack.yaml.lock new file mode 100644 index 0000000..39112d0 --- /dev/null +++ b/stack.yaml.lock @@ -0,0 +1,40 @@ +# This file was autogenerated by Stack. +# You should not edit this file by hand. +# For more information, please see the documentation at: +# https://docs.haskellstack.org/en/stable/lock_files + +packages: +- completed: + hackage: clash-ghc-1.6.4@sha256:43e4c9c949bf9623633f08bb09bb4495578b517be4e99140d9ea22dd2a9cd13b,9042 + pantry-tree: + sha256: 9484d37cd6c8cb0217a02cf020b6398dbe1a68fa332472b40cfb511ce54a743a + size: 3634 + original: + hackage: clash-ghc-1.6.4 +- completed: + hackage: clash-prelude-1.6.4@sha256:67b5c26ad7c712e23f5d54187d691cbb007931a89b4aabd4a738c307d71b2a27,17249 + pantry-tree: + sha256: b12774016a4f9bd456ecdf7bc1e5182d33ef4ac9e16db0f344d27189a26bfe2d + size: 13292 + original: + hackage: clash-prelude-1.6.4 +- completed: + hackage: clash-lib-1.6.4@sha256:336e57d424852f2ad9285b6fa820e634f32d39d52755d3245d5f4ac04ea37f85,13688 + pantry-tree: + sha256: 750ffc9d2f5ed3690f6a2a7da46090970594dbbcf8a6b55d785e8f809b4dfbf1 + size: 22460 + original: + hackage: clash-lib-1.6.4 +- completed: + hackage: concurrent-supply-0.1.8@sha256:9373f4868ad28936a7b93781b214ef4afdeacf377ef4ac729583073491c9f9fb,1627 + pantry-tree: + sha256: bdfaa167ae3249f858ba248aea2e9b97ab9b13af6e68c73b7c3192e717e11b83 + size: 400 + original: + hackage: concurrent-supply-0.1.8 +snapshots: +- completed: + sha256: 6d1532d40621957a25bad5195bfca7938e8a06d923c91bc52aa0f3c41181f2d4 + size: 619204 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/19/33.yaml + original: lts-19.33 diff --git a/test/Main.hs b/test/Main.hs deleted file mode 100644 index 3e2059e..0000000 --- a/test/Main.hs +++ /dev/null @@ -1,4 +0,0 @@ -module Main (main) where - -main :: IO () -main = putStrLn "Test suite not yet implemented." diff --git a/tests/Tests/Example/Project.hs b/tests/Tests/Example/Project.hs new file mode 100644 index 0000000..dcce6a3 --- /dev/null +++ b/tests/Tests/Example/Project.hs @@ -0,0 +1,26 @@ +module Tests.Example.Project where + +import Prelude + +import Test.Tasty +import Test.Tasty.TH +import Test.Tasty.Hedgehog + +import Hedgehog ((===)) +import qualified Hedgehog as H +import qualified Hedgehog.Gen as Gen +import qualified Hedgehog.Range as Range + +import Example.Project (plus) + +prop_plusIsCommutative :: H.Property +prop_plusIsCommutative = H.property $ do + a <- H.forAll (Gen.integral (Range.linear minBound maxBound)) + b <- H.forAll (Gen.integral (Range.linear minBound maxBound)) + plus a b === plus b a + +tests :: TestTree +tests = $(testGroupGenerator) + +main :: IO () +main = defaultMain tests diff --git a/tests/doctests.hs b/tests/doctests.hs new file mode 100644 index 0000000..c577e91 --- /dev/null +++ b/tests/doctests.hs @@ -0,0 +1,8 @@ +module Main where + +import System.Environment (getArgs) +import Test.DocTest (mainFromCabal) + +main :: IO () +main = mainFromCabal "simple" =<< getArgs + diff --git a/tests/unittests.hs b/tests/unittests.hs new file mode 100644 index 0000000..bb3fa79 --- /dev/null +++ b/tests/unittests.hs @@ -0,0 +1,10 @@ +import Prelude + +import Test.Tasty + +import qualified Tests.Example.Project + +main :: IO () +main = defaultMain $ testGroup "." + [ Tests.Example.Project.tests + ]