Skip to content

Commit 3d80373

Browse files
committed
Use (:>) in favor of Cons
1 parent f166a20 commit 3d80373

File tree

23 files changed

+174
-179
lines changed

23 files changed

+174
-179
lines changed

clash-lib/src/Clash/Core/TermLiteral.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import Clash.Core.Term (Term(Literal, Data), collectAr
5252
import Clash.Promoted.Nat
5353
import Clash.Promoted.Nat.Unsafe
5454
import Clash.Sized.Index (Index)
55-
import Clash.Sized.Vector (Vec (Nil, Cons), fromList)
55+
import Clash.Sized.Vector (Vec (Nil, (:>)), fromList)
5656
import qualified Clash.Util.Interpolate as I
5757
import qualified Clash.Verification.Internal as Cv
5858

@@ -193,7 +193,7 @@ instance (TermLiteral a, KnownNat n) => TermLiteral (Vec n a) where
193193
case constr of
194194
Data (MkData{dcName=Name{nameOcc}})
195195
| nameOcc == showt 'Nil -> Right []
196-
| nameOcc == showt 'Cons ->
196+
| nameOcc == showt '(:>) ->
197197
case lefts args of
198198
[_gadtProof, c0, cs0] -> do
199199
c1 <- termToData @a c0

clash-lib/src/Clash/Core/Util.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ unsafeCoerceTy =
9898

9999
-- | Create a vector of supplied elements
100100
mkVec :: DataCon -- ^ The Nil constructor
101-
-> DataCon -- ^ The Cons (:>) constructor
101+
-> DataCon -- ^ The (:>) constructor
102102
-> Type -- ^ Element type
103103
-> Integer -- ^ Length of the vector
104104
-> [Term] -- ^ Elements to put in the vector
@@ -128,7 +128,7 @@ mkVec nilCon consCon resTy = go
128128
_ -> error "impossible"
129129

130130
-- | Append elements to the supplied vector
131-
appendToVec :: DataCon -- ^ The Cons (:>) constructor
131+
appendToVec :: DataCon -- ^ The (:>) constructor
132132
-> Type -- ^ Element type
133133
-> Term -- ^ The vector to append the elements to
134134
-> Integer -- ^ Length of the vector
@@ -161,7 +161,7 @@ extractElems
161161
-> InScopeSet
162162
-- ^ (Superset of) in scope variables
163163
-> DataCon
164-
-- ^ The Cons (:>) constructor
164+
-- ^ The (:>) constructor
165165
-> Type
166166
-- ^ The element type
167167
-> Char
@@ -609,10 +609,10 @@ shouldSplit0 tcm (TyConApp tcNm tyArgs)
609609
-- Project the n'th value out of a vector
610610
--
611611
-- >>> mkVecSelector subj 0
612-
-- case subj of Cons x xs -> x
612+
-- case subj of x :> xs -> x
613613
--
614614
-- >>> mkVecSelector subj 2
615-
-- case (case (case subj of Cons x xs -> xs) of Cons x xs -> xs) of Cons x xs -> x
615+
-- case (case (case subj of x :> xs -> xs) of x :> xs -> xs) of x :> xs -> x
616616
mkVecSelector :: forall m . MonadUnique m => InScopeSet -> Term -> Integer -> m Term
617617
mkVecSelector is0 subj 0 =
618618
mkSelectorCase ($(curLoc) ++ "mkVecSelector") is0 tcm subj 2 1

clash-lib/src/Clash/Netlist.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,10 +1056,10 @@ mkDcApplication declType [dstHType] bndr dc args = do
10561056
Vector 0 _ -> return (HW.DataCon dstHType VecAppend [])
10571057
Vector 1 _ -> case argExprsFiltered of
10581058
[e] -> return (HW.DataCon dstHType VecAppend [e])
1059-
_ -> error $ $(curLoc) ++ "Unexpected number of arguments for `Cons`: " ++ showPpr args
1059+
_ -> error $ $(curLoc) ++ "Unexpected number of arguments for `(:>)`: " ++ showPpr args
10601060
Vector _ _ -> case argExprsFiltered of
10611061
[e1,e2] -> return (HW.DataCon dstHType VecAppend [e1,e2])
1062-
_ -> error $ $(curLoc) ++ "Unexpected number of arguments for `Cons`: " ++ showPpr args
1062+
_ -> error $ $(curLoc) ++ "Unexpected number of arguments for `(:>)`: " ++ showPpr args
10631063
MemBlob _ _ ->
10641064
case compare 6 (length argExprsFiltered) of
10651065
EQ -> return (HW.DataCon dstHType (DC (dstHType,0)) argExprsFiltered)

clash-lib/src/Clash/Netlist/Util.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ mkADT builtInTranslation reprs m tyString tc args = case tyConDataCons (UniqMap.
538538
-- data Vec :: Nat -> Type -> Type
539539
-- where
540540
-- Nil :: Vec 0 a
541-
-- Cons :: forall m . (n ~ m + 1) => a -> Vec m a -> Vec n a
541+
-- (:>) :: forall m . (n ~ m + 1) => a -> Vec m a -> Vec n a
542542
--
543543
-- where we can generate a type for `m` when we know `n` (by doing `n-1`).
544544
--

clash-lib/src/Clash/Normalize/PrimitiveReductions.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ vecTailTy vecNm =
184184
-- vector, the latter the tail.
185185
extractHeadTail
186186
:: DataCon
187-
-- ^ The Cons (:>) constructor
187+
-- ^ The (:>) constructor
188188
-> Type
189189
-- ^ Element type
190190
-> Integer
@@ -206,15 +206,15 @@ extractHeadTail consCon elTy n vec =
206206
in
207207
( Case vec elTy [(pat, Var el)]
208208
, Case vec restTy [(pat, Var rest)] )
209-
_ -> error "extractHeadTail: failed to instantiate Cons DC"
209+
_ -> error "extractHeadTail: failed to instantiate (:>) DC"
210210
where
211211
tys = [(LitTy (NumTy n)), elTy, (LitTy (NumTy (n-1)))]
212212

213213
-- | Create a vector of supplied elements
214214
mkVecCons
215215
:: HasCallStack
216216
=> DataCon
217-
-- ^ The Cons (:>) constructor
217+
-- ^ The (:>) constructor
218218
-> Type
219219
-- ^ Element type
220220
-> Integer
@@ -235,7 +235,7 @@ mkVecCons consCon resTy n h t
235235
, Left (primCo consCoTy)
236236
, Left h
237237
, Left t ]
238-
_ -> error "mkVecCons: failed to instantiate Cons DC"
238+
_ -> error "mkVecCons: failed to instantiate (:>) DC"
239239

240240
-- | Create an empty vector
241241
mkVecNil
@@ -568,7 +568,7 @@ reduceTraverse n aTy fTy bTy dict fun arg (TransformContext is0 ctx) = do
568568
-- > (:>) <$> x0 <*> ((:>) <$> x1 <*> pure Nil)
569569
mkTravVec :: TyConName -- ^ Vec tcon
570570
-> DataCon -- ^ Nil con
571-
-> DataCon -- ^ Cons con
571+
-> DataCon -- ^ (:>) con
572572
-> Term -- ^ 'pure' term
573573
-> Term -- ^ '<*>' term
574574
-> Term -- ^ 'fmap' term
@@ -983,7 +983,7 @@ reduceUnconcat unconcatPrimInfo n m aTy _kn sm arg (TransformContext inScope _ct
983983
, Left (snd nextVec)
984984
]
985985
-- let (mvec,nextVec) = splitAt sm arg
986-
-- in Cons mvec (unconcat sm nextVec)
986+
-- in mvec :> (unconcat sm nextVec)
987987
lBody = mkVecCons consCon innerVecTy n mvec nextUnconcat
988988
lb = Letrec lbs lBody
989989

clash-lib/src/Clash/Normalize/Transformations/Case.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -670,24 +670,24 @@ caseOneAlt e = return e
670670
-- existential should be. For example, consider Vec:
671671
--
672672
-- data Vec :: Nat -> Type -> Type where
673-
-- Nil :: Vec 0 a
674-
-- Cons x xs :: a -> Vec n a -> Vec (n + 1) a
673+
-- Nil :: Vec 0 a
674+
-- x :> xs :: a -> Vec n a -> Vec (n + 1) a
675675
--
676676
-- Thus, 'null' (annotated with existentials) could look like:
677677
--
678678
-- null :: forall n . Vec n Bool -> Bool
679679
-- null v =
680680
-- case v of
681681
-- Nil {n ~ 0} -> True
682-
-- Cons {n1:Nat} {n~n1+1} (x :: a) (xs :: Vec n1 a) -> False
682+
-- (:>) {n1:Nat} {n~n1+1} (x :: a) (xs :: Vec n1 a) -> False
683683
--
684684
-- When it's applied to a vector of length 5, this becomes:
685685
--
686686
-- null :: Vec 5 Bool -> Bool
687687
-- null v =
688688
-- case v of
689689
-- Nil {5 ~ 0} -> True
690-
-- Cons {n1:Nat} {5~n1+1} (x :: a) (xs :: Vec n1 a) -> False
690+
-- (:>) {n1:Nat} {5~n1+1} (x :: a) (xs :: Vec n1 a) -> False
691691
--
692692
-- This function solves 'n1' and replaces every occurrence with its solution. A
693693
-- very limited number of solutions are currently recognized: only adds (such

clash-lib/src/Clash/Normalize/Transformations/Letrec.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import qualified Data.Text.Extra as Text
4040
import GHC.Stack (HasCallStack)
4141

4242
import Clash.Annotations.BitRepresentation.Deriving (dontApplyInHDL)
43-
import Clash.Sized.Vector as Vec (Vec(Cons), splitAt)
43+
import Clash.Sized.Vector as Vec (Vec((:>)), splitAt)
4444

4545
import Clash.Annotations.Primitive (extractPrim)
4646
import Clash.Core.DataCon (DataCon(..))
@@ -151,9 +151,9 @@ removeUnusedExpr _ e@(Case _ _ [(DataPat _ [] xs,altExpr)]) =
151151
else return e
152152

153153
-- Replace any expression that creates a Vector of size 0 within the application
154-
-- of the Cons constructor, by the Nil constructor.
154+
-- of the (:>) constructor, by the Nil constructor.
155155
removeUnusedExpr _ e@(collectArgsTicks -> (Data dc, [_,Right aTy,Right nTy,_,Left a,Left nil],ticks))
156-
| nameOcc (dcName dc) == Text.showt 'Vec.Cons
156+
| nameOcc (dcName dc) == Text.showt '(Vec.:>)
157157
= do
158158
tcm <- Lens.view tcCache
159159
case runExcept (tyNatSize tcm nTy) of

clash-prelude/src/Clash/Explicit/SimIO.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,9 @@ getLine (File fp) (Reg r) = SimIO $ do
279279
return 0
280280
where
281281
rep :: String -> Vec m (Unsigned 8) -> Vec m (Unsigned 8)
282-
rep [] vs = vs
283-
rep (x:xs) (Cons _ vs) = Cons (toEnum (fromEnum x)) (rep xs vs)
284-
rep _ Nil = Nil
282+
rep [] vs = vs
283+
rep (x:xs) (_ :> vs) = toEnum (fromEnum x) :> rep xs vs
284+
rep _ Nil = Nil
285285
-- See: https://github.com/clash-lang/clash-compiler/pull/2511
286286
{-# CLASH_OPAQUE getLine #-}
287287
{-# ANN getLine hasBlackBox #-}

0 commit comments

Comments
 (0)