Skip to content

Commit

Permalink
Use prettyprinter-interp (#2428)
Browse files Browse the repository at this point in the history
When we splice a `string-interpolate` quasi quoter into a
`prettyprinter` `Doc`, it is more efficient to use the
`prettyprinter-interp` quasi quoter wrappers.
  • Loading branch information
DigitalBrains1 authored Mar 22, 2023
1 parent e0da461 commit 4791875
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 33 deletions.
1 change: 1 addition & 0 deletions .ci/stack-8.10.7.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ extra-deps:
- doctest-parallel-0.2.1@sha256:c6c0d095dd6e0b8ce1bd9f6f5fc4e0cf5cf50b6895b557356ac41b8aa2947399,5631
- fakedata-1.0.2@sha256:37c93be9a81acbc9109e2c0b300a793d9c1f5ead1d34330d869d76568191f428,24593
- docopt-0.7.0.7@sha256:a3d2eac54cd77d8c0b306ff96fb57be55542f143d81766aa1ae51458ad790dbe,3655
- prettyprinter-interp-0.2.0.0@sha256:45299b61bd6c27d594c1a72b5a8dd5734e791a59828725e4f4e420f3cc37232b,2016
1 change: 1 addition & 0 deletions .ci/stack-8.6.5.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ extra-deps:
- regex-tdfa-1.3.1.2@sha256:9bafdeace4742f553d22a3da008081ac09009b3b52d38a53ad76795dfd3f180a,6572
- regex-base-0.94.0.2@sha256:4ff4425c710cddf440dfbac6cd52310bb6b23e17902390ff71c9fc7eaafc4fcc,2643
- string-interpolate-0.3.1.2@sha256:4d0987f453c66040aa8e482fe28a7d3cdc9d8df01b698bc92f42a592cfb337db,4268
- prettyprinter-interp-0.2.0.0@sha256:45299b61bd6c27d594c1a72b5a8dd5734e791a59828725e4f4e420f3cc37232b,2016
1 change: 1 addition & 0 deletions .ci/stack-8.8.4.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ extra-deps:
- lazysmallcheck-0.6@sha256:dac7a1e4877681f1260309e863e896674dd6efc1159897b7945893e693f2a6bc,1696
- docopt-0.7.0.7@sha256:a3d2eac54cd77d8c0b306ff96fb57be55542f143d81766aa1ae51458ad790dbe,3655
- string-interpolate-0.3.1.2@sha256:4d0987f453c66040aa8e482fe28a7d3cdc9d8df01b698bc92f42a592cfb337db,4268
- prettyprinter-interp-0.2.0.0@sha256:45299b61bd6c27d594c1a72b5a8dd5734e791a59828725e4f4e420f3cc37232b,2016
3 changes: 3 additions & 0 deletions .ci/stack-9.0.2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ packages:
- clash-ghc
- clash-cores
- tests

extra-deps:
- prettyprinter-interp-0.2.0.0@sha256:45299b61bd6c27d594c1a72b5a8dd5734e791a59828725e4f4e420f3cc37232b,2016
1 change: 1 addition & 0 deletions .ci/stack-9.2.4.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ packages:
extra-deps:
- concurrent-supply-0.1.8@sha256:9373f4868ad28936a7b93781b214ef4afdeacf377ef4ac729583073491c9f9fb,1627
- hashable-1.3.5.0@sha256:3a2beeafb220f9de706568a7e4a5b3c762cc4c9f25c94d7ef795b8c2d6a691d7,4240
- prettyprinter-interp-0.2.0.0@sha256:45299b61bd6c27d594c1a72b5a8dd5734e791a59828725e4f4e420f3cc37232b,2016
2 changes: 1 addition & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ write-ghc-environment-files: always
-- index state, to go along with the cabal.project.freeze file. update the index
-- state by running `cabal update` twice and looking at the index state it
-- displays to you (as the second update will be a no-op)
index-state: 2022-12-23T12:46:44Z
index-state: 2023-02-25T00:27:36Z

-- For some reason the `clash-testsuite` executable fails to run without
-- this, as it cannot find the related library...
Expand Down
1 change: 1 addition & 0 deletions clash-cores/clash-cores.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ library
clash-lib,
mtl >= 2.1.1 && < 2.3,
prettyprinter >= 1.2.0.1 && < 1.8,
prettyprinter-interp ^>= 0.2,
reducers >= 3.12.2 && < 4.0,
text >= 1.2.2 && < 1.3

Expand Down
10 changes: 5 additions & 5 deletions clash-cores/src/Clash/Cores/Xilinx/Floating/BlackBoxes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import Prelude
import Control.Monad.State (State)
import Data.Maybe (isJust, fromJust)
import Data.String (fromString, IsString)
import Data.String.Interpolate (i, __i)
import Prettyprinter.Interpolate (di, __di)

import Clash.Backend (Backend)
import Clash.Netlist.Types
Expand Down Expand Up @@ -152,7 +152,7 @@ tclTemplate (HasCustom {..}) operType bbCtx
prop (True, name, value) s =
replicate 29 ' ' ++ name ++ ' ': value ++ " \\\n" ++ s

bbText = [i|namespace eval $tclIface {
bbText = [di|namespace eval $tclIface {
variable api 1
variable scriptPurpose createIp
variable ipName {#{compName}}
Expand Down Expand Up @@ -193,7 +193,7 @@ fromUTclTemplate bbCtx
(DataCon _ _ [Literal Nothing (BoolLit True)], _, _) -> "false"
_ -> "true"

bbText = [__i|
bbText = [__di|
namespace eval $tclIface {
variable api 1
variable scriptPurpose createIp
Expand Down Expand Up @@ -245,7 +245,7 @@ fromSTclTemplate bbCtx
(DataCon _ _ [Literal Nothing (BoolLit True)], _, _) -> "false"
_ -> "true"

bbText = [__i|
bbText = [__di|
namespace eval $tclIface {
variable api 1
variable scriptPurpose createIp
Expand Down Expand Up @@ -296,7 +296,7 @@ compareTclTemplate bbCtx
(DataCon _ _ [Literal Nothing (BoolLit True)], _, _) -> "false"
_ -> "true"

bbText = [__i|
bbText = [__di|
namespace eval $tclIface {
variable api 1
variable scriptPurpose createIp
Expand Down
9 changes: 5 additions & 4 deletions clash-cores/src/Clash/Cores/Xilinx/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module Clash.Cores.Xilinx.Internal where

import Prelude
import Data.Maybe (catMaybes)
import Data.String.Interpolate (i, __i)
import Data.Text (Text)
import qualified Data.Text as Text
#if MIN_VERSION_prettyprinter(1,7,0)
Expand All @@ -29,6 +28,8 @@ import Data.Text.Prettyprint.Doc
import Data.Text.Prettyprint.Doc.Extra (Doc)
import GHC.Natural (Natural)
import GHC.Stack (HasCallStack)
import Prettyprinter.Interpolate (di, __di)

import Clash.Netlist.Types (IdentifierText)

type PropName = Text
Expand Down Expand Up @@ -166,7 +167,7 @@ renderTcl = \case
indent 2 "variable scriptPurpose multipleScripts" <> line <> rbrace <>
line <> vsep ms
where
rootSnippet = [__i|
rootSnippet = [__di|
namespace eval $tclIface {
variable api 1
|]
Expand All @@ -176,7 +177,7 @@ renderTcl = \case
indent 2 "return" <> line <> rbrace
where
-- \& is needed to prevent CPP from joining lines :-(
ipSnippet = [__i|
ipSnippet = [__di|
variable scriptPurpose createIp
variable ipName {#{moduleName}}
proc createIp {ipName0 args} {
Expand Down Expand Up @@ -208,5 +209,5 @@ renderTcl = \case
]

renderMulti n p =
line <> [i|namespace eval ${tclIface}::multipleScripts::script#{n} {|] <>
line <> [di|namespace eval ${tclIface}::multipleScripts::script#{n} {|] <>
line <> indent 2 (renderOne p) <> line <> rbrace
1 change: 1 addition & 0 deletions clash-lib/clash-lib.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ Library
mtl >= 2.1.2 && < 2.3,
ordered-containers >= 0.2 && < 0.3,
prettyprinter >= 1.2.0.1 && < 1.8,
prettyprinter-interp ^>= 0.2,
pretty-show >= 1.9 && < 2.0,
primitive >= 0.5.0.1 && < 1.0,
template-haskell >= 2.8.0.0 && < 2.19,
Expand Down
5 changes: 3 additions & 2 deletions clash-lib/src/Clash/Primitives/Intel/ClockGen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import Control.Monad.State
import Data.Monoid (Ap(getAp))
import qualified Data.String.Interpolate as I
import Data.Text.Prettyprint.Doc.Extra
import qualified Prettyprinter.Interpolate as I

import qualified Data.Text as TextS
import Data.Text.Extra (showt)
Expand Down Expand Up @@ -176,7 +177,7 @@ altpllQsysTemplate bbCtx = case bbInputs bbCtx of
-- "altpll" IP. Module parameters were then stripped on a trial-and-error
-- basis to get a template that has the minimal number of parameters, but
-- still has the desired, working, configuration.
bbText = [I.__i|
bbText = [I.__di|
<?xml version="1.0" encoding="UTF-8"?>
<system name="$${FILENAME}">
<module
Expand Down Expand Up @@ -277,7 +278,7 @@ alteraPllQsysTemplate bbCtx = case bbInputs bbCtx of
]

-- See Note [QSys file templates] on how this qsys template was derived.
bbText = [I.__i|
bbText = [I.__di|
<?xml version="1.0" encoding="UTF-8"?>
<system name="$${FILENAME}">
<module
Expand Down
3 changes: 3 additions & 0 deletions nix/nixpkgs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ let
doctest-parallel =
self.callCabal2nix "doctest-parallel" sources.doctest-parallel {};

prettyprinter-interp =
self.callCabal2nix "prettyprinter-interp" sources.prettyprinter-interp {};

tasty-hedgehog =
self.callCabal2nix "tasty-hedgehog" sources.tasty-hedgehog {};

Expand Down
54 changes: 33 additions & 21 deletions nix/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"homepage": null,
"owner": "martijnbastiaan",
"repo": "doctest-parallel",
"rev": "112b85b55c63dae1cc52b5216efe03873f1acc06",
"sha256": "1v18an5np0wflg6phycmmhqmcpmn30p0vxaq2wx8ha5af8ckmymb",
"rev": "cfadbd95748ee00bab15b7ab00ccae3d86b7add9",
"sha256": "1bwj42fnlz0wx0gfpj1cmrrjb9qxfnl6ivg834jziqz4av8w262h",
"type": "tarball",
"url": "https://github.com/martijnbastiaan/doctest-parallel/archive/112b85b55c63dae1cc52b5216efe03873f1acc06.tar.gz",
"url": "https://github.com/martijnbastiaan/doctest-parallel/archive/cfadbd95748ee00bab15b7ab00ccae3d86b7add9.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"ghc-tcplugins-extra": {
Expand All @@ -17,10 +17,10 @@
"homepage": null,
"owner": "clash-lang",
"repo": "ghc-tcplugins-extra",
"rev": "631facf6160f87e481c25ea76094c8a01d85f990",
"sha256": "0mhf86japnxrqahlj68w4s12lss637pi3xyysvaz0xrf4yr1wa1m",
"rev": "c2007b347c9cff4637709907010d309f68401f2a",
"sha256": "0q7c8kk58sg1xazcrmjch1h655jx2canrnfj7npinmm853rnnm8c",
"type": "tarball",
"url": "https://github.com/clash-lang/ghc-tcplugins-extra/archive/631facf6160f87e481c25ea76094c8a01d85f990.tar.gz",
"url": "https://github.com/clash-lang/ghc-tcplugins-extra/archive/c2007b347c9cff4637709907010d309f68401f2a.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"ghc-typelits-extra": {
Expand All @@ -29,10 +29,10 @@
"homepage": null,
"owner": "clash-lang",
"repo": "ghc-typelits-extra",
"rev": "fe80881503c8ba80c86f17fbdaf481dcd1304d44",
"sha256": "1vg9kj34iyjdbmvs71nr3jh11r963an1c8vcx4j1zr3w8h3sbjkj",
"rev": "d4a66e64944b7ab84d18450f2c9130a36e2c5917",
"sha256": "091kvzlpzhy6l0qcsk6gwksnlg53272xnzag1r1xxl825my6hcav",
"type": "tarball",
"url": "https://github.com/clash-lang/ghc-typelits-extra/archive/fe80881503c8ba80c86f17fbdaf481dcd1304d44.tar.gz",
"url": "https://github.com/clash-lang/ghc-typelits-extra/archive/d4a66e64944b7ab84d18450f2c9130a36e2c5917.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"ghc-typelits-knownnat": {
Expand All @@ -41,10 +41,10 @@
"homepage": null,
"owner": "clash-lang",
"repo": "ghc-typelits-knownnat",
"rev": "fb94131ac8beaf6167fc2cc5f94602cc881950df",
"sha256": "1mknsldr99qp4494vxqdjw0v97mzjhsmi3mfcp0h5qbdv11z1qhc",
"rev": "0cf1cc089db84431ecb54b5bfc6171375f1f6ec4",
"sha256": "0q13vh6d5l2nnhack47kfgkykb3x8lbsanpcd6158g5fbhjqvrlf",
"type": "tarball",
"url": "https://github.com/clash-lang/ghc-typelits-knownnat/archive/fb94131ac8beaf6167fc2cc5f94602cc881950df.tar.gz",
"url": "https://github.com/clash-lang/ghc-typelits-knownnat/archive/0cf1cc089db84431ecb54b5bfc6171375f1f6ec4.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"ghc-typelits-natnormalise": {
Expand All @@ -53,10 +53,10 @@
"homepage": null,
"owner": "clash-lang",
"repo": "ghc-typelits-natnormalise",
"rev": "48c69dfe3e7c523b1e5268008571fd17d89d2d58",
"sha256": "0r0ky6fcwpabj2kdb8yb8h4731vc06qz3gf89c44mjc042pnmd5q",
"rev": "f089f6bd91af2038cdc5b60f28d10bc8d1079a23",
"sha256": "18kc71gasmpqic0lxwhsian1j3a0i2zlbm09hhfi258ih9bi7dq8",
"type": "tarball",
"url": "https://github.com/clash-lang/ghc-typelits-natnormalise/archive/48c69dfe3e7c523b1e5268008571fd17d89d2d58.tar.gz",
"url": "https://github.com/clash-lang/ghc-typelits-natnormalise/archive/f089f6bd91af2038cdc5b60f28d10bc8d1079a23.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"gitignore": {
Expand All @@ -77,10 +77,10 @@
"homepage": "https://github.com/nmattia/niv",
"owner": "nmattia",
"repo": "niv",
"rev": "82e5cd1ad3c387863f0545d7591512e76ab0fc41",
"sha256": "090l219mzc0gi33i3psgph6s2pwsc8qy4lyrqjdj4qzkvmaj65a7",
"rev": "689d0e5539eddd0b0f566aee7bb18629eee7df74",
"sha256": "1rld3lk42l6b01f2gcrhq8qm9vry1awmfl29zmpiqda9dy89vbx0",
"type": "tarball",
"url": "https://github.com/nmattia/niv/archive/82e5cd1ad3c387863f0545d7591512e76ab0fc41.tar.gz",
"url": "https://github.com/nmattia/niv/archive/689d0e5539eddd0b0f566aee7bb18629eee7df74.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"nixpkgs": {
Expand All @@ -89,10 +89,22 @@
"homepage": null,
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "3321eea12a97a31a04b419108564ca1b8cca193c",
"sha256": "12pil3zaq7ap9q9782zqxgbr1b8mwlnc0mwlbh0paacbgkgc3sbf",
"rev": "0874168639713f547c05947c76124f78441ea46c",
"sha256": "0gw5l5bj3zcgxhp7ki1jafy6sl5nk4vr43hal94lhi15kg2vfmfy",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/3321eea12a97a31a04b419108564ca1b8cca193c.tar.gz",
"url": "https://github.com/NixOS/nixpkgs/archive/0874168639713f547c05947c76124f78441ea46c.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"prettyprinter-interp": {
"branch": "main",
"description": "Efficient interpolation for Prettyprinter",
"homepage": null,
"owner": "DigitalBrains1",
"repo": "prettyprinter-interp",
"rev": "0a4056f3f22ca5c3baa28fa1ec3d1d0d9b6802dd",
"sha256": "0krn2bjdj01rxz1613w9qnhfdgr05r14hdf1rfg93qgfrnac9y2k",
"type": "tarball",
"url": "https://github.com/DigitalBrains1/prettyprinter-interp/archive/0a4056f3f22ca5c3baa28fa1ec3d1d0d9b6802dd.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"tasty-hedgehog": {
Expand Down
1 change: 1 addition & 0 deletions stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ packages:

extra-deps:
- ./clash-cosim
- prettyprinter-interp-0.2.0.0@sha256:45299b61bd6c27d594c1a72b5a8dd5734e791a59828725e4f4e420f3cc37232b,2016

0 comments on commit 4791875

Please sign in to comment.