{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-warnings-deprecations #-}

module Protolude.Debug (
  undefined,
  trace,
  traceM,
  traceId,
  traceIO,
  traceShow,
  traceShowId,
  traceShowM,
  notImplemented,
  witness,
) where

import Data.Text (Text, unpack)
import Control.Monad (Monad, return)

import qualified Protolude.Base as P
import Protolude.Error (error)
import Protolude.Show (Print, hPutStrLn)

import System.IO(stderr)
import System.IO.Unsafe (unsafePerformIO)

{-# WARNING trace "'trace' remains in code" #-}
trace :: Print b => b -> a -> a
trace :: b -> a -> a
trace b
string a
expr = IO a -> a
forall a. IO a -> a
unsafePerformIO (do
    Handle -> b -> IO ()
forall a (m :: * -> *). (Print a, MonadIO m) => Handle -> a -> m ()
hPutStrLn Handle
stderr b
string
    a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return a
expr)

{-# WARNING traceIO "'traceIO' remains in code" #-}
traceIO :: Print b => b -> a -> P.IO a
traceIO :: b -> a -> IO a
traceIO b
string a
expr = do
    Handle -> b -> IO ()
forall a (m :: * -> *). (Print a, MonadIO m) => Handle -> a -> m ()
hPutStrLn Handle
stderr b
string
    a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return a
expr

{-# WARNING traceShow "'traceShow' remains in code" #-}
traceShow :: P.Show a => a -> b -> b
traceShow :: a -> b -> b
traceShow a
a b
b = String -> b -> b
forall b a. Print b => b -> a -> a
trace (a -> String
forall a. Show a => a -> String
P.show a
a) b
b

{-# WARNING traceShowId "'traceShowId' remains in code" #-}
traceShowId :: P.Show a => a -> a
traceShowId :: a -> a
traceShowId a
a = String -> a -> a
forall b a. Print b => b -> a -> a
trace (a -> String
forall a. Show a => a -> String
P.show a
a) a
a

{-# WARNING traceShowM "'traceShowM' remains in code" #-}
traceShowM :: (P.Show a, Monad m) => a -> m ()
traceShowM :: a -> m ()
traceShowM a
a = String -> m () -> m ()
forall b a. Print b => b -> a -> a
trace (a -> String
forall a. Show a => a -> String
P.show a
a) (() -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ())

{-# WARNING traceM "'traceM' remains in code" #-}
traceM :: (Monad m) => Text -> m ()
traceM :: Text -> m ()
traceM Text
s = String -> m () -> m ()
forall b a. Print b => b -> a -> a
trace (Text -> String
unpack Text
s) (() -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ())

{-# WARNING traceId "'traceId' remains in code" #-}
traceId :: Text -> Text
traceId :: Text -> Text
traceId Text
s = Text -> Text -> Text
forall b a. Print b => b -> a -> a
trace Text
s Text
s

{-# WARNING notImplemented "'notImplemented' remains in code" #-}
notImplemented :: a
notImplemented :: a
notImplemented = Text -> a
forall a. HasCallStack => Text -> a
error Text
"Not implemented"

{-# WARNING undefined "'undefined' remains in code" #-}
undefined :: a
undefined :: a
undefined = Text -> a
forall a. HasCallStack => Text -> a
error Text
"Prelude.undefined"

witness :: a
witness :: a
witness = Text -> a
forall a. HasCallStack => Text -> a
error Text
"Type witness should not be evaluated"