Skip to content

Commit 9e1386c

Browse files
committed
Bump typelit plugins (preparations)
1 parent 5ec337c commit 9e1386c

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

clash-prelude/src/Clash/Sized/Vector.hs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2654,17 +2654,32 @@ dtfold :: forall p k a . KnownNat k
26542654
dtfold _ f g = go (SNat :: SNat k)
26552655
where
26562656
go :: forall n . SNat n -> Vec (2^n) a -> (p @@ n)
2657-
go _ (x `Cons` Nil) = f x
2658-
go sn xs@(Cons _ (Cons _ _)) =
2659-
let sn' :: SNat (n - 1)
2660-
sn' = sn `subSNat` d1
2661-
(xsL,xsR) = splitAt (pow2SNat sn') xs
2662-
in g sn' (go sn' xsL) (go sn' xsR)
2657+
go sn = case toUNat sn of
2658+
UZero -> \case
2659+
Cons x Nil -> f x
2660+
Cons x (Cons _ _) -> f x
2661+
USucc _ -> \case
2662+
xs@(Cons _ (Cons _ _)) ->
2663+
let sn' :: SNat (n - 1)
2664+
sn' = sn `subSNat` d1
2665+
(xsL,xsR) = splitAt (pow2SNat sn') xs
2666+
in g sn' (go sn' xsL) (go sn' xsR)
2667+
-- the remaining cases are impossible cases, but GHC cannot
2668+
-- automatically detect them to be inaccesible. We need to
2669+
-- give additional evidence for proving them to be absurd.
2670+
Cons _ Nil -> case p0 sn of Dict -> case p1 sn of {}
2671+
where
2672+
p0 :: 1 <= m => SNat m -> Dict (2 <= 2^((m-1)+1))
2673+
p0 = const Dict
2674+
p1 :: 1 <= m => SNat m -> Dict (2^m ~ 2^((m-1)+1))
2675+
p1 = const Dict
26632676
#if !MIN_VERSION_base(4,16,0) || MIN_VERSION_base(4,17,0)
2664-
go _ Nil =
2665-
case (const Dict :: forall m. Proxy m -> Dict (1 <= 2 ^ m)) (Proxy @n) of
2666-
{}
2677+
Nil -> case p sn of {}
2678+
where
2679+
p :: SNat m -> Dict (1 <= 2^m)
2680+
p = const Dict
26672681
#endif
2682+
26682683
-- See: https://github.com/clash-lang/clash-compiler/pull/2511
26692684
{-# CLASH_OPAQUE dtfold #-}
26702685
{-# ANN dtfold hasBlackBox #-}

0 commit comments

Comments
 (0)