Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simulation/Synthesis mismatch for X-exception to undefined bitvector conversion #2154

Closed
christiaanb opened this issue Mar 30, 2022 · 1 comment
Labels

Comments

@christiaanb
Copy link
Member

The following:

module TQQ where

import Clash.Explicit.Prelude

topEntity (clk :: Clock System) rst =
  let r = unpack (pack ( errorX "QQ" :: (Index 10)
                       , 3 :: Index 10
                       )) :: Vec 2 (Index 10)
      s = register clk rst enableGen (seq r r) s
   in s

results in:

                Unmatchable constant as case subject: Clash.Sized.Vector.unconcatBitVector# @2
                  @(Clash.Class.BitPack.Internal.BitSize[8214565720323787922]
                      (Clash.Sized.Internal.Index.Index[8214565720323788072]
                         10))
                  (Clash.Normalize.Primitives.removedArg
                     @GHC.Natural.Natural[3674937295934324786])
                  4
                  (Clash.Sized.Internal.BitVector.++#
                     @(Clash.Class.BitPack.Internal.BitSize[8214565720323787922]
                         (Clash.Sized.Internal.Index.Index[8214565720323788072]
                            10))
                     @(Clash.Class.BitPack.Internal.BitSize[8214565720323787922]
                         (Clash.Sized.Internal.Index.Index[8214565720323788072]
                            10))
                     (Clash.Normalize.Primitives.removedArg
                        @(GHC.TypeLits.KnownNat.SNatKn[8214565720323785195]
                            "GHC.TypeLits.Extra.CLog"))
                     (Clash.Sized.Internal.Index.pack# @10
                        (Clash.XException.errorX
                           @(Clash.Sized.Internal.Index.Index[8214565720323788072]
                               10)
                           (Clash.Normalize.Primitives.removedArg
                              @GHC.Stack.Types.CallStack[3674937295934325108])
                           (Clash.Normalize.Primitives.removedArg
                              @(GHC.Types.[][3674937295934324788]
                                  GHC.Types.Char[3674937295934324752]))))
                     (Clash.Sized.Internal.BitVector.fromInteger#
                        @(GHC.TypeLits.Extra.CLog[8214565720323785180]
                            2
                            10)
                        4
                        0
                        3))
                WHNF is: Clash.Sized.Vector.unconcatBitVector# @2
                  @(Clash.Class.BitPack.Internal.BitSize[8214565720323787922]
                      (Clash.Sized.Internal.Index.Index[8214565720323788072]
                         10))
                  (Clash.Normalize.Primitives.removedArg
                     @GHC.Natural.Natural[3674937295934324786])
                  4
                  (Clash.Sized.Internal.BitVector.++#
                     @(Clash.Class.BitPack.Internal.BitSize[8214565720323787922]
                         (Clash.Sized.Internal.Index.Index[8214565720323788072]
                            10))
                     @(Clash.Class.BitPack.Internal.BitSize[8214565720323787922]
                         (Clash.Sized.Internal.Index.Index[8214565720323788072]
                            10))
                     (Clash.Normalize.Primitives.removedArg
                        @(GHC.TypeLits.KnownNat.SNatKn[8214565720323785195]
                            "GHC.TypeLits.Extra.CLog"))
                     (Clash.Sized.Internal.Index.pack# @10
                        (Clash.XException.errorX
                           @(Clash.Sized.Internal.Index.Index[8214565720323788072]
                               10)
                           (Clash.Normalize.Primitives.removedArg
                              @GHC.Stack.Types.CallStack[3674937295934325108])
                           (Clash.Normalize.Primitives.removedArg
                              @(GHC.Types.[][3674937295934324788]
                                  GHC.Types.Char[3674937295934324752]))))
                     (Clash.Sized.Internal.BitVector.fromInteger#
                        @(GHC.TypeLits.Extra.CLog[8214565720323785180]
                            2
                            10)
                        4
                        0
                        3))
                
                /home/christiaan/devel/clash-compiler/tests/shouldwork/Issues/TQQ.hs:6:1: error:
                    
                    Clash.Netlist.BlackBox(213): Couldn't instantiate blackbox for Clash.Signal.Internal.register#. Verification procedure reported:
                    
                    Argument 5 should be literal, as blackbox used ~CONST[5], but was:
                    
                    DataCon (Vector 2 (Index 10)) VecAppend [BlackBoxE "Clash.Sized.Internal.Index.unpack#" [] [] [] BBTemplate [Text "unsigned(",Arg 2,Text ")"] (Context {bbName = "Clash.Sized.Internal.Index.unpack#", bbResults = [(Identifier (RawIdentifier "s_4" Nothing [("unsafeMake",SrcLoc {srcLocPackage = "clash-lib-1.7.0-inplace", srcLocModule = "Clash.Netlist.Util", srcLocFile = "src/Clash/Netlist/Util.hs", srcLocStartLine = 1003, srcLocStartCol = 17, srcLocEndLine = 1003, srcLocEndCol = 30})]) Nothing,Index 10)], bbInputs = [(BlackBoxE "Clash.Normalize.Primitives.removedArg" [] [] [] BBTemplate [Err Nothing] (Context {bbName = "Clash.Normalize.Primitives.removedArg", bbResults = [(Identifier (RawIdentifier "s_4" Nothing [("unsafeMake",SrcLoc {srcLocPackage = "clash-lib-1.7.0-inplace", srcLocModule = "Clash.Netlist.Util", srcLocFile = "src/Clash/Netlist/Util.hs", srcLocStartLine = 1003, srcLocStartCol = 17, srcLocEndLine = 1003, srcLocEndCol = 30})]) Nothing,Unsigned 64)], bbInputs = [], bbFunctions = fromList [], bbQsysIncName = [], bbLevel = 0, bbCompName = UniqueIdentifier {i_baseName = "topEntity", i_baseNameCaseFold = "topentity", i_extensionsRev = [], i_idType = Basic, i_hdl = VHDL, i_provenance = [("make##",SrcLoc {srcLocPackage = "clash-lib-1.7.0-inplace", srcLocModule = "Clash.Netlist.Id.Internal", srcLocFile = "src/Clash/Netlist/Id/Internal.hs", srcLocStartLine = 129, srcLocStartCol = 9, srcLocEndLine = 129, srcLocEndCol = 73}),("make#",SrcLoc {srcLocPackage = "clash-lib-1.7.0-inplace", srcLocModule = "Clash.Netlist.Id.Internal", srcLocFile = "src/Clash/Netlist/Id/Internal.hs", srcLocStartLine = 133, srcLocStartCol = 18, srcLocEndLine = 133, srcLocEndCol = 27}),("makeBasic#",SrcLoc {srcLocPackage = "clash-lib-1.7.0-inplace", srcLocModule = "Clash.Netlist.Id", srcLocFile = "src/Clash/Netlist/Id.hs", srcLocStartLine = 179, srcLocStartCol = 32, srcLocEndLine = 179, srcLocEndCol = 42}),("makeBasic",SrcLoc {srcLocPackage = "clash-lib-1.7.0-inplace", srcLocModule = "Clash.Netlist", srcLocFile = "src/Clash/Netlist.hs", srcLocStartLine = 247, srcLocStartCol = 14, srcLocEndLine = 247, srcLocEndCol = 62})]}, bbCtxName = Just "s_4"}) True,Unsigned 64,True),(Identifier (RawIdentifier "__VOID__" Nothing [("unsafeMake",SrcLoc {srcLocPackage = "clash-lib-1.7.0-inplace", srcLocModule = "Clash.Netlist.BlackBox", srcLocFile = "src/Clash/Netlist/BlackBox.hs", srcLocStartLine = 490, srcLocStartCol = 52, srcLocEndLine = 490, srcLocEndCol = 76})]) Nothing,Void (Just (Product "GHC.Types.~" Nothing [Void Nothing])),False),(Identifier (UniqueIdentifier {i_baseName = "s_res", i_baseNameCaseFold = "s_res", i_extensionsRev = [], i_idType = Basic, i_hdl = VHDL, i_provenance = [("make##",SrcLoc {srcLocPackage = "clash-lib-1.7.0-inplace", srcLocModule = "Clash.Netlist.Id.Internal", srcLocFile = "src/Clash/Netlist/Id/Internal.hs", srcLocStartLine = 129, srcLocStartCol = 9, srcLocEndLine = 129, srcLocEndCol = 73}),("make#",SrcLoc {srcLocPackage = "clash-lib-1.7.0-inplace", srcLocModule = "Clash.Netlist.Id.Internal", srcLocFile = "src/Clash/Netlist/Id/Internal.hs", srcLocStartLine = 171, srcLocStartCol = 27, srcLocEndLine = 171, srcLocEndCol = 71}),("suffix#",SrcLoc {srcLocPackage = "clash-lib-1.7.0-inplace", srcLocModule = "Clash.Netlist.Id", srcLocFile = "src/Clash/Netlist/Id.hs", srcLocStartLine = 226, srcLocStartCol = 53, srcLocEndLine = 226, srcLocEndCol = 75}),("suffix",SrcLoc {srcLocPackage = "clash-lib-1.7.0-inplace", srcLocModule = "Clash.Netlist.BlackBox", srcLocFile = "src/Clash/Netlist/BlackBox.hs", srcLocStartLine = 693, srcLocStartCol = 22, srcLocEndLine = 693, srcLocEndCol = 42})]}) (Just (Indexed (Vector 2 (BitVector 4),1,0))),BitVector 4,False)], bbFunctions = fromList [], bbQsysIncName = [], bbLevel = 0, bbCompName = UniqueIdentifier {i_baseName = "topEntity", i_baseNameCaseFold = "topentity", i_extensionsRev = [], i_idType = Basic, i_hdl = VHDL, i_provenance = [("make##",SrcLoc {srcLocPackage = "clash-lib-1.7.0-inplace", srcLocModule = "Clash.Netlist.Id.Internal", srcLocFile = "src/Clash/Netlist/Id/Internal.hs", srcLocStartLine = 129, srcLocStartCol = 9, srcLocEndLine = 129, srcLocEndCol = 73}),("make#",SrcLoc {srcLocPackage = "clash-lib-1.7.0-inplace", srcLocModule = "Clash.Netlist.Id.Internal", srcLocFile = "src/Clash/Netlist/Id/Internal.hs", srcLocStartLine = 133, srcLocStartCol = 18, srcLocEndLine = 133, srcLocEndCol = 27}),("makeBasic#",SrcLoc {srcLocPackage = "clash-lib-1.7.0-inplace", srcLocModule = "Clash.Netlist.Id", srcLocFile = "src/Clash/Netlist/Id.hs", srcLocStartLine = 179, srcLocStartCol = 32, srcLocEndLine = 179, srcLocEndCol = 42}),("makeBasic",SrcLoc {srcLocPackage = "clash-lib-1.7.0-inplace", srcLocModule = "Clash.Netlist", srcLocFile = "src/Clash/Netlist.hs", srcLocStartLine = 247, srcLocStartCol = 14, srcLocEndLine = 247, srcLocEndCol = 62})]}, bbCtxName = Just "s_4"}) False,DataCon (Vector 1 (Index 10)) VecAppend [BlackBoxE "Clash.Sized.Internal.Index.unpack#" [] [] [] BBTemplate [Text "unsigned(",Arg 2,Text ")"] (Context {bbName = "Clash.Sized.Internal.Index.unpack#", bbResults = [(Identifier (RawIdentifier "s_4" Nothing [("unsafeMake",SrcLoc {srcLocPackage = "clash-lib-1.7.0-inplace", srcLocModule = "Clash.Netlist.Util", srcLocFile = "src/Clash/Netlist/Util.hs", srcLocStartLine = 1003, srcLocStartCol = 17, srcLocEndLine = 1003, srcLocEndCol = 30})]) Nothing,Index 10)], bbInputs = [(BlackBoxE "Clash.Normalize.Primitives.removedArg" [] [] [] BBTemplate [Err Nothing] (Context {bbName = "Clash.Normalize.Primitives.removedArg", bbResults = [(Identifier (RawIdentifier "s_4" Nothing [("unsafeMake",SrcLoc {srcLocPackage = "clash-lib-1.7.0-inplace", srcLocModule = "Clash.Netlist.Util", srcLocFile = "src/Clash/Netlist/Util.hs", srcLocStartLine = 1003, srcLocStartCol = 17, srcLocEndLine = 1003, srcLocEndCol = 30})]) Nothing,Unsigned 64)], bbInputs = [], bbFunctions = fromList [], bbQsysIncName = [], bbLevel = 0, bbCompName = UniqueIdentifier {i_baseName = "topEntity", i_baseNameCaseFold = "topentity", i_extensionsRev = [], i_idType = Basic, i_hdl = VHDL, i_provenance = [("make##",SrcLoc {srcLocPackage = "clash-lib-1.7.0-inplace", srcLocModule = "Clash.Netlist.Id.Internal", srcLocFile = "src/Clash/Netlist/Id/Internal.hs", srcLocStartLine = 129, srcLocStartCol = 9, srcLocEndLine = 129, srcLocEndCol = 73}),("make#",SrcLoc {srcLocPackage = "clash-lib-1.7.0-inplace", srcLocModule = "Clash.Netlist.Id.Internal", srcLocFile = "src/Clash/Netlist/Id/Internal.hs", srcLocStartLine = 133, srcLocStartCol = 18, srcLocEndLine = 133, srcLocEndCol = 27}),("makeBasic#",SrcLoc {srcLocPackage = "clash-lib-1.7.0-inplace", srcLocModule = "Clash.Netlist.Id", srcLocFile = "src/Clash/Netlist/Id.hs", srcLocStartLine = 179, srcLocStartCol = 32, srcLocEndLine = 179, srcLocEndCol = 42}),("makeBasic",SrcLoc {srcLocPackage = "clash-lib-1.7.0-inplace", srcLocModule = "Clash.Netlist", srcLocFile = "src/Clash/Netlist.hs", srcLocStartLine = 247, srcLocStartCol = 14, srcLocEndLine = 247, srcLocEndCol = 62})]}, bbCtxName = Just "s_4"}) True,Unsigned 64,True),(Identifier (RawIdentifier "__VOID__" Nothing [("unsafeMake",SrcLoc {srcLocPackage = "clash-lib-1.7.0-inplace", srcLocModule = "Clash.Netlist.BlackBox", srcLocFile = "src/Clash/Netlist/BlackBox.hs", srcLocStartLine = 490, srcLocStartCol = 52, srcLocEndLine = 490, srcLocEndCol = 76})]) Nothing,Void (Just (Product "GHC.Types.~" Nothing [Void Nothing])),False),(Identifier (UniqueIdentifier {i_baseName = "s_res", i_baseNameCaseFold = "s_res", i_extensionsRev = [0], i_idType = Basic, i_hdl = VHDL, i_provenance = [("mkUnique#",SrcLoc {srcLocPackage = "clash-lib-1.7.0-inplace", srcLocModule = "Clash.Netlist.Id.Internal", srcLocFile = "src/Clash/Netlist/Id/Internal.hs", srcLocStartLine = 165, srcLocStartCol = 19, srcLocEndLine = 165, srcLocEndCol = 77}),("deepen#",SrcLoc {srcLocPackage = "clash-lib-1.7.0-inplace", srcLocModule = "Clash.Netlist.Id.Internal", srcLocFile = "src/Clash/Netlist/Id/Internal.hs", srcLocStartLine = 123, srcLocStartCol = 5, srcLocEndLine = 123, srcLocEndCol = 20}),("make#",SrcLoc {srcLocPackage = "clash-lib-1.7.0-inplace", srcLocModule = "Clash.Netlist.Id.Internal", srcLocFile = "src/Clash/Netlist/Id/Internal.hs", srcLocStartLine = 171, srcLocStartCol = 27, srcLocEndLine = 171, srcLocEndCol = 71}),("suffix#",SrcLoc {srcLocPackage = "clash-lib-1.7.0-inplace", srcLocModule = "Clash.Netlist.Id", srcLocFile = "src/Clash/Netlist/Id.hs", srcLocStartLine = 226, srcLocStartCol = 53, srcLocEndLine = 226, srcLocEndCol = 75}),("suffix",SrcLoc {srcLocPackage = "clash-lib-1.7.0-inplace", srcLocModule = "Clash.Netlist.BlackBox", srcLocFile = "src/Clash/Netlist/BlackBox.hs", srcLocStartLine = 693, srcLocStartCol = 22, srcLocEndLine = 693, srcLocEndCol = 42})]}) (Just (Nested (Indexed (Vector 2 (BitVector 4),1,1)) (Indexed (Vector 1 (BitVector 4),1,0)))),BitVector 4,False)], bbFunctions = fromList [], bbQsysIncName = [], bbLevel = 0, bbCompName = UniqueIdentifier {i_baseName = "topEntity", i_baseNameCaseFold = "topentity", i_extensionsRev = [], i_idType = Basic, i_hdl = VHDL, i_provenance = [("make##",SrcLoc {srcLocPackage = "clash-lib-1.7.0-inplace", srcLocModule = "Clash.Netlist.Id.Internal", srcLocFile = "src/Clash/Netlist/Id/Internal.hs", srcLocStartLine = 129, srcLocStartCol = 9, srcLocEndLine = 129, srcLocEndCol = 73}),("make#",SrcLoc {srcLocPackage = "clash-lib-1.7.0-inplace", srcLocModule = "Clash.Netlist.Id.Internal", srcLocFile = "src/Clash/Netlist/Id/Internal.hs", srcLocStartLine = 133, srcLocStartCol = 18, srcLocEndLine = 133, srcLocEndCol = 27}),("makeBasic#",SrcLoc {srcLocPackage = "clash-lib-1.7.0-inplace", srcLocModule = "Clash.Netlist.Id", srcLocFile = "src/Clash/Netlist/Id.hs", srcLocStartLine = 179, srcLocStartCol = 32, srcLocEndLine = 179, srcLocEndCol = 42}),("makeBasic",SrcLoc {srcLocPackage = "clash-lib-1.7.0-inplace", srcLocModule = "Clash.Netlist", srcLocFile = "src/Clash/Netlist.hs", srcLocStartLine = 247, srcLocStartCol = 14, srcLocEndLine = 247, srcLocEndCol = 62})]}, bbCtxName = Just "s_4"}) False]]
                    
                    The source location of the error is not exact, only indicative, as it is acquired 
                    after optimizations. The actual location of the error can be in a function that is 
                    inlined. To prevent inlining of those functions, annotate them with a NOINLINE pragma.
                  |
                6 | topEntity (clk :: Clock System) rst =
                  | ^^^^^^^^^
christiaanb added a commit that referenced this issue Mar 30, 2022
christiaanb added a commit that referenced this issue Mar 30, 2022
christiaanb added a commit that referenced this issue Mar 30, 2022
christiaanb added a commit that referenced this issue Mar 31, 2022
christiaanb added a commit that referenced this issue Mar 31, 2022
christiaanb added a commit that referenced this issue Mar 31, 2022
christiaanb added a commit that referenced this issue Apr 4, 2022
mergify bot pushed a commit that referenced this issue Apr 4, 2022
Fixes #2154

(cherry picked from commit e6f8124)
@martijnbastiaan
Copy link
Member

We've released v1.6.3, which includes a fix for this issue.

lmbollen added a commit to bittide/bittide-hardware that referenced this issue Apr 21, 2022
Clash bug [#2154](clash-lang/clash-compiler#2154) prevented synthesis.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants