You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following program causes the compiler to fail with an "empty list" error from Data.List.init:
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE UndecidableInstances #-}
moduleTestwhereimportClash.Sized.RTreeasRTreeimportClash.PreludeimportData.Functor.ComposeimportData.ProxyimportData.Singletons.Prelude (type (@@), TyFun, Apply)
importData.Singletons.TypeLits (withKnownNat)
importData.Kind (Constraint, Type)
importDebug.Trace
{-# ANN test
((defSyn "test")
{ t_name = "test"
, t_inputs = [ PortName "clock"
, PortName "reset"
, PortName "x"
, PortName "y"
]
, t_output = PortName "out"
})
#-}
test::ClockSystemSource->ResetSystemSynchronous->SignalSystem (UnsignedN)
->SignalSystem (UnsignedN)
->SignalSystem (UnsignedN)
test clk reset x y = withClockReset clk reset $fmapfromIntegral$ mul' @4@_@4 x y
main =dolet ns = (,) <$> [100,200,300,400] <*> [0..10]
print$fmap (uncurry(*)) ns
print$ simulate (uncurry (mul' @4@16@24) . unbundle) ns
mul'::forallchunkSznmnChunksdomgatedsynth.
(KnownNatchunkSz, KnownNatn, KnownNatm, KnownNatnChunks,
HiddenClockResetdomgatedsynth,
(2^m) ~ (chunkSz*nChunks), 1<=nChunks, ObviousnChunks)
=>Signaldom (Unsigned (2^n))
->Signaldom (Unsigned (2^m))
->Signaldom (Unsigned (2^(n+m+1)))
mul' x y =fmapfromIntegral$ delayBy (SNat@1)
$ sumTree
$sequenceA$fmap (vecToRTree 0)
$ delayBy (SNat@2) res'
wherechunks::Unsigned (2^m) ->VecnChunks (UnsignedchunkSz)
chunks n = bitChunks n
chunkSz =fromIntegral$ natVal $Proxy@chunkSzpartial::Unsigned (2^n) ->IndexnChunks->UnsignedchunkSz->Unsigned (2^(n+chunkSz))
partial y i x =fromIntegral (y `mul` x) `shiftL` (chunkSz *fromIntegral i)
res::Signaldom (VecnChunks (Unsigned (2^(n+chunkSz))))
res =zipWith3 partial
<$>fmappure x
<*>pure indicesI
<*>fmap chunks y
res'::Signaldom (VecnChunks (Unsigned (2^(n+m+1))))
res' =fmap (fmapfromIntegral) res
--| Latency of @d@.sumTree::foralldndomsynthgated.
(KnownNatd, KnownNatn, HiddenClockResetdomsynthgated)
=>RTreed (Signaldom (Unsignedn))
->Signaldom (Unsigned (n+d))
sumTree rtree =
tdfold (Proxy@(IAccumdomn)) id f rtree
wheref::foralll.()=>SNatl->IAccumdomn@@l->IAccumdomn@@l->IAccumdomn@@ (l+1)
f lvl@SNat l r = add <$> delayBy lvl l <*> delayBy lvl r
dataIAccum (dom::Domain) (n::Nat) (f::TyFunNatType) ::TypetypeinstanceApply (IAccumdomn) l=Signaldom (Unsigned (n+l))
vecToRTree::forallna. (KnownNatn, 1<=n, Obviousn)
=>a->Vecna->RTree (CLog2n) a
vecToRTree z = v2t . pad
wherepad::Vecna->Vec (2^(CLog2n)) a
pad x = x ++ (repeat z ::Vec (2^(CLog2n) -n) a)
typeObviousn= ((n<=2^(CLog2n)) ::Constraint)
bitChunks::forallmn. (KnownNatm, KnownNatn)
=>Unsigned (m*n) ->Vecm (Unsignedn)
bitChunks x =reverse$fmap (\i ->fromIntegral$ x `shiftR` (fromIntegral i*n)) indicesI
where
n =fromIntegral$ natVal $Proxy@ndelayBy::forallndomagated. (Undefineda, HiddenClockdomgated)
=>SNatn->Signaldoma->Signaldoma
delayBy n =foldr(.)id (replicate n delay)
naive::HiddenClockResetdomgatedsynth=>Signaldom (Unsigned16)
->Signaldom (Unsigned16)
->Signaldom (Unsigned16)
naive x y = delayBy (SNat@16) $ x*y
typeN=16
The error appears to come from
*** Exception (reporting due to +RTS -xc): (THUNK_STATIC), stack trace:
Clash.Main.main'.\,
called from Clash.Main.handleClashException,
called from Clash.Util.traceIf,
called from Clash.Normalize.PrimitiveReductions.reduceFoldr.go,
called from Clash.Normalize.PrimitiveReductions.reduceFoldr,
called from Clash.Rewrite.Types.>>=.\,
called from Clash.Rewrite.Types.>>=,
called from Clash.Driver.normalizeEntity.doNorm,
called from Clash.Rewrite.Util.runRewriteSession.(...),
called from Clash.Rewrite.Util.runRewriteSession,
called from Clash.Normalize.runNormalization,
called from Clash.Driver.normalizeEntity.transformedBindings,
called from Clash.Driver.normalizeEntity,
called from Clash.Driver.generateHDL.go.transformedBindings,
called from Clash.Driver.generateHDL.go,
called from Clash.Driver.generateHDL,
called from Clash.GHCi.UI.makeHDL.\,
called from Clash.GHCi.UI.makeHDL,
called from Clash.Main.makeHDL',
called from Clash.Main.makeVerilog,
called from Clash.Main.main'.clash,
called from Clash.Main.main',
called from Clash.Main.defaultMain,
called from Main.main
I added a bit of tracing to the call site with the following patch,
diff --git a/clash-lib/src/Clash/Normalize/PrimitiveReductions.hs b/clash-lib/src/Clash/Normalize/PrimitiveReductions.hs
index 206f9482..ed694e9f 100644
--- a/clash-lib/src/Clash/Normalize/PrimitiveReductions.hs+++ b/clash-lib/src/Clash/Normalize/PrimitiveReductions.hs@@ -303,6 +310,14 @@ reduceFoldr n aTy fun start arg = do
where
go tcm (coreView tcm -> Just ty') = go tcm ty'
go tcm (tyView -> TyConApp vecTcNm _)
+ | (Just vecTc) <- HashMap.lookup (nameOcc vecTcNm) tcm+ , [_,consCon] <- tyConDataCons vecTc+ , let (vars,elems) = second concat . unzip+ $ extractElems consCon aTy 'G' n arg+ , [] <- elems+ = error $ "reduceFoldr: n="++show n++", ty="++showDoc aTy++", fun="+++ showDoc fun++", start="++showDoc start++", arg="++showDoc arg+
| (Just vecTc) <- HashMap.lookup (nameOcc vecTcNm) tcm
, [_,consCon] <- tyConDataCons vecTc
= let (vars,elems) = second concat . unzip
Which yielded the following,
<no location info>: error:
Clash error call:
reduceFoldr: n=0, ty=Clash.Signal.Internal.Signal
(Clash.Signal.Internal.Dom system 10000)
(Clash.Sized.Internal.Unsigned.Unsigned 512)
-> Clash.Signal.Internal.Signal
(Clash.Signal.Internal.Dom system 10000)
(Clash.Sized.Internal.Unsigned.Unsigned 512), fun=GHC.Base..8214565720323787974
@(Clash.Signal.Internal.Signal
(Clash.Signal.Internal.Dom system 10000)
(Clash.Sized.Internal.Unsigned.Unsigned 512))
@(Clash.Signal.Internal.Signal
(Clash.Signal.Internal.Dom system 10000)
(Clash.Sized.Internal.Unsigned.Unsigned 512))
@(Clash.Signal.Internal.Signal
(Clash.Signal.Internal.Dom system 10000)
(Clash.Sized.Internal.Unsigned.Unsigned 512)), start=GHC.Base.id8214565720323787481
@(Clash.Signal.Internal.Signal
(Clash.Signal.Internal.Dom system 10000)
(Clash.Sized.Internal.Unsigned.Unsigned 512)), arg=Clash.Sized.Vector.replicate @0
@(Clash.Signal.Internal.Signal
(Clash.Signal.Internal.Dom system 10000)
(Clash.Sized.Internal.Unsigned.Unsigned 512)
-> Clash.Signal.Internal.Signal
(Clash.Signal.Internal.Dom system 10000)
(Clash.Sized.Internal.Unsigned.Unsigned 512))
(Clash.Promoted.Nat.SNat @0
0)
(?(i :: Clash.Signal.Internal.Signal
(Clash.Signal.Internal.Dom system 10000)
(Clash.Sized.Internal.Unsigned.Unsigned 512)) ->
Clash.Signal.Internal.delay#
@(Clash.Sized.Internal.Unsigned.Unsigned 512)
@(Clash.Signal.Internal.Dom system 10000)
@Clash.Signal.Internal.Source
GHC.Stack.Types.EmptyCallStack
(?($dIP :: GHC.Classes.IP
callStack
GHC.Stack.Types.CallStack) ->
?(eta :: GHC.Types.[] GHC.Types.Char) ->
case $dIP of
_ ->
Clash.Sized.Internal.Unsigned.$fUndefinedUnsigned18214565720323812782
@512
$dIP
eta
GHC.Stack.Types.FreezeCallStack
(ds1 :: GHC.Stack.Types.CallStack) ->
Clash.XException.errorX
@(Clash.Sized.Internal.Unsigned.Unsigned 512)
$dIP
eta)
$dIP41933
i)
The text was updated successfully, but these errors were encountered:
The following program causes the compiler to fail with an "empty list" error from
Data.List.init
:The error appears to come from
I added a bit of tracing to the call site with the following patch,
Which yielded the following,
The text was updated successfully, but these errors were encountered: