From fc4727d98c544480f49f7c1b439832043bf34dfb Mon Sep 17 00:00:00 2001 From: Christiaan Baaij Date: Fri, 14 Jul 2023 18:35:54 +0200 Subject: [PATCH] Make `imap_go` eval rule lazy in index argument (#2543) Fixes #2542 The problem was that in the final recursive call, when `imap_go` would return `Nil`, the index argument was out-of-bounds. And because `imap_go` was strict in all arguments, `imap_go` would make the `Nil` undefined. Subsequently applying `reverse` where the `Nil` is undefined, gives us a complete vector that is undefined, given that `reverse` is strict in its vector argument. (cherry picked from commit a1dacb46446b3c3c841dc4b174a3b1a719632717) # Conflicts: # clash-ghc/src-ghc/Clash/GHC/Evaluator/Primitive.hs # tests/Main.hs --- clash-ghc/src-ghc/Clash/GHC/Evaluator/Primitive.hs | 13 +++++++++++++ tests/Main.hs | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/clash-ghc/src-ghc/Clash/GHC/Evaluator/Primitive.hs b/clash-ghc/src-ghc/Clash/GHC/Evaluator/Primitive.hs index 141111aca6..99b2d4f2ef 100644 --- a/clash-ghc/src-ghc/Clash/GHC/Evaluator/Primitive.hs +++ b/clash-ghc/src-ghc/Clash/GHC/Evaluator/Primitive.hs @@ -2,7 +2,13 @@ Copyright : (C) 2013-2016, University of Twente, 2016-2017, Myrtle Software Ltd, 2017-2022, Google Inc., +<<<<<<< HEAD 2017-2024, QBayLogic B.V. +||||||| parent of a1dacb46 (Make `imap_go` eval rule lazy in index argument (#2543)) + 2017-2022, QBayLogic B.V. +======= + 2017-2023, QBayLogic B.V. +>>>>>>> a1dacb46 (Make `imap_go` eval rule lazy in index argument (#2543)) License : BSD2 (see the file LICENSE) Maintainer : QBayLogic B.V. -} @@ -202,8 +208,15 @@ ghcPrimUnwind tcm p tys vs v [e] m0 , "Clash.Sized.Vector.replace_int" , "GHC.Classes.&&" , "GHC.Classes.||" +<<<<<<< HEAD , showt 'BitVector.xToBV , "Clash.Sized.Vector.imap_go" +||||||| parent of a1dacb46 (Make `imap_go` eval rule lazy in index argument (#2543)) + , "Clash.Class.BitPack.Internal.xToBV" +======= + , "Clash.Class.BitPack.Internal.xToBV" + , "Clash.Sized.Vector.imap_go" +>>>>>>> a1dacb46 (Make `imap_go` eval rule lazy in index argument (#2543)) ] = if isUndefinedPrimVal v then let tyArgs = map Right tys diff --git a/tests/Main.hs b/tests/Main.hs index 33a4d91433..000c93716d 100755 --- a/tests/Main.hs +++ b/tests/Main.hs @@ -816,6 +816,7 @@ runClashTest = defaultMain } , outputTest "T2510" def{hdlTargets=[VHDL], clashFlags=["-DNOINLINE=OPAQUE"]} #endif +<<<<<<< HEAD , outputTest "T2542" def{hdlTargets=[VHDL]} , runTest "T2593" def{hdlSim=[]} , runTest "T2623CaseConFVs" def{hdlLoad=[],hdlSim=[],hdlTargets=[VHDL]} @@ -824,6 +825,10 @@ runClashTest = defaultMain , runTest "T2839" def{hdlLoad=[],hdlSim=[],hdlTargets=[VHDL]} , runTest "T2845" def{hdlSim=[],hdlTargets=[Verilog]} , runTest "T2831" def{hdlLoad=[],hdlSim=[],hdlTargets=[VHDL]} +||||||| parent of a1dacb46 (Make `imap_go` eval rule lazy in index argument (#2543)) +======= + , outputTest "T2542" def{hdlTargets=[VHDL]} +>>>>>>> a1dacb46 (Make `imap_go` eval rule lazy in index argument (#2543)) ] <> if compiledWith == Cabal then -- This tests fails without environment files present, which are only