@@ -26,6 +26,12 @@ module Clash.Normalize.Transformations.Case
2626 , elimExistentials
2727 ) where
2828
29+ import Control.Exception.Base (patError )
30+ #if MIN_VERSION_base(4,16,0)
31+ import GHC.Prim.Panic (absentError )
32+ #else
33+ import Control.Exception.Base (absentError )
34+ #endif
2935import qualified Control.Lens as Lens
3036import Control.Monad.State.Strict (evalState )
3137import Data.Bifunctor (second )
@@ -80,6 +86,8 @@ import Clash.Rewrite.Util (changed, isFromInt, whnfRW)
8086import Clash.Rewrite.WorkFree
8187import Clash.Util (curLoc )
8288
89+ import Clash.XException (errorX )
90+
8391-- | Move a Case-decomposition from the subject of a Case-decomposition to the
8492-- alternatives
8593caseCase :: HasCallStack => NormRewrite
@@ -266,27 +274,23 @@ caseCon' ctx@(TransformContext is0 _) e@(Case subj ty alts) = do
266274 -- WHNF of subject is _|_, in the form of `error`: that means that the
267275 -- entire case-expression is evaluates to _|_
268276 (Prim pInfo,repTy: _: callStack: msg: _,ticks)
269- | primName pInfo `elem` [" GHC.Err.error"
270- ," GHC.Internal.Err.error" ] ->
277+ | primName pInfo == Text. showt 'error ->
271278 let e1 = mkApps (mkTicks (Prim pInfo) ticks)
272279 [repTy,Right ty,callStack,msg]
273280 in changed e1
274281 -- WHNF of subject is _|_, in the form of `absentError`: that means that
275282 -- the entire case-expression is evaluates to _|_
276283 (Prim pInfo,_: msgOrCallStack: _,ticks)
277- | primName pInfo `elem` [" Control.Exception.Base.absentError"
278- ," GHC.Prim.Panic.absentError" ] ->
284+ | primName pInfo == Text. showt 'absentError ->
279285 let e1 = mkApps (mkTicks (Prim pInfo) ticks)
280286 [Right ty,msgOrCallStack]
281287 in changed e1
282288 -- WHNF of subject is _|_, in the form of `patError`, `undefined`, or
283289 -- `errorWithoutStackTrace`: that means the entire case-expression is _|_
284290 (Prim pInfo,repTy: _: msgOrCallStack: _,ticks)
285- | primName pInfo `elem` [" Control.Exception.Base.patError"
286- ," GHC.Err.undefined"
287- ," GHC.Err.errorWithoutStackTrace"
288- ," GHC.Internal.Err.undefined"
289- ," GHC.Internal.Err.errorWithoutStackTrace" ] ->
291+ | primName pInfo `elem` [ Text. showt 'patError
292+ , Text. showt 'undefined
293+ , Text. showt 'errorWithoutStackTrace] ->
290294 let e1 = mkApps (mkTicks (Prim pInfo) ticks)
291295 [repTy,Right ty,msgOrCallStack]
292296 in changed e1
@@ -300,7 +304,7 @@ caseCon' ctx@(TransformContext is0 _) e@(Case subj ty alts) = do
300304 -- WHNF of subject is _|_, in the form of `errorX`: that means that
301305 -- the entire case-expression is evaluates to _|_
302306 (Prim pInfo,_: callStack: msg: _,ticks)
303- | primName pInfo == " Clash.XException. errorX"
307+ | primName pInfo == Text. showt ' errorX
304308 -> let e1 = mkApps (mkTicks (Prim pInfo) ticks) [Right ty,callStack,msg]
305309 in changed e1
306310 -- WHNF of subject is non of the above, so either a variable reference,
0 commit comments