Skip to content

Commit

Permalink
exitImmediately
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPenner committed Nov 14, 2024
1 parent c63facc commit ccfd180
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions unison-runtime/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ library:
when:
- condition: false
other-modules: Paths_unison_runtime
- condition: flag(stackchecks)
dependencies:
- unix

dependencies:
- asn1-encoding
Expand Down Expand Up @@ -78,6 +81,7 @@ library:
- unison-syntax
- unison-util-bytes
- unison-util-recursion
- unix
- unliftio
- vector
- crypton-x509
Expand Down
10 changes: 8 additions & 2 deletions unison-runtime/src/Unison/Runtime/Stack.hs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ import Prelude hiding (words)

{- ORMOLU_DISABLE -}
#ifdef STACK_CHECK
import System.Posix.Process qualified as Posix
import Unison.Debug qualified as Debug
import Data.Text.IO (hPutStrLn)
import UnliftIO (stderr)

type DebugCallStack = (HasCallStack :: Constraint)

Expand All @@ -159,7 +162,8 @@ assertBumped (Stack _ _ sp ustk bstk) i = do
u <- readByteArray ustk (sp - i)
b :: BVal <- readArray bstk (sp - i)
when (u /= unboxedSentinel || not (isBoxedSentinel b)) do
error $ "Expected stack slot to have been bumped, but it was:" <> show (Val u b)
hPutStrLn stderr $ "Expected stack slot to have been bumped, but it was:" <> (tShow (Val u b))
Posix.exitImmediately (ExitFailure 456)
where
isBoxedSentinel :: Closure -> Bool
isBoxedSentinel (Closure GUnboxedSentinel) = True
Expand All @@ -171,7 +175,9 @@ assertUnboxed (Stack _ _ sp ustk bstk) i = do
b <- readArray bstk (sp - i)
case b of
UnboxedTypeTag _ -> pure ()
_ -> error $ "Expected stack val to be unboxed, but it was:" <> show (Val u b)
_ -> do
hPutStrLn stderr $ "Expected stack val to be unboxed, but it was:" <> tShow (Val u b)
Posix.exitImmediately (ExitFailure 456)

pokeSentinelOff :: Stack -> Off -> IO ()
pokeSentinelOff (Stack _ _ sp ustk bstk) off = do
Expand Down
4 changes: 4 additions & 0 deletions unison-runtime/unison-runtime.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ library
, unison-syntax
, unison-util-bytes
, unison-util-recursion
, unix
, unliftio
, vector
default-language: Haskell2010
Expand All @@ -148,6 +149,9 @@ library
cpp-options: -DARRAY_CHECK
if flag(stackchecks)
cpp-options: -DSTACK_CHECK
if flag(stackchecks)
build-depends:
unix

test-suite runtime-tests
type: exitcode-stdio-1.0
Expand Down

0 comments on commit ccfd180

Please sign in to comment.