{-# LANGUAGE OverloadedStrings #-}

-- | This module is distinct from "Unison.Runtime.Exception" because that depends on "Unison.Runtime.Stack", which would
--   cause an import cycle.
module Unison.Runtime.InternalError
  ( CompileExn (CE),
    internalBug,
  )
where

import Control.Exception (throw)
import GHC.Stack (CallStack, callStack)
import Unison.Prelude

data CompileExn = CE CallStack [Word] String
  deriving (Int -> CompileExn -> ShowS
[CompileExn] -> ShowS
CompileExn -> String
(Int -> CompileExn -> ShowS)
-> (CompileExn -> String)
-> ([CompileExn] -> ShowS)
-> Show CompileExn
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CompileExn -> ShowS
showsPrec :: Int -> CompileExn -> ShowS
$cshow :: CompileExn -> String
show :: CompileExn -> String
$cshowList :: [CompileExn] -> ShowS
showList :: [CompileExn] -> ShowS
Show)

instance Exception CompileExn

internalBug :: (HasCallStack) => [Word] -> String -> a
internalBug :: forall a. HasCallStack => [Word] -> String -> a
internalBug [Word]
issues = CompileExn -> a
forall a e. Exception e => e -> a
throw (CompileExn -> a) -> (String -> CompileExn) -> String -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CallStack -> [Word] -> String -> CompileExn
CE CallStack
HasCallStack => CallStack
callStack [Word]
issues