Skip to content

Commit

Permalink
PR Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPenner committed Nov 27, 2024
1 parent deb544c commit cc68b25
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 18 deletions.
2 changes: 0 additions & 2 deletions unison-runtime/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ github: unisonweb/unison
copyright: Copyright (C) 2013-2024 Unison Computing, PBC and contributors

ghc-options: -fmax-worker-args=100 -Wall -funbox-strict-fields -O2
# -fsimpl-tick-factor=300 -fmax-simplifier-iterations=10 -fspecialise-aggressively -fexpose-all-unfoldings

flags:
arraychecks:
Expand Down Expand Up @@ -124,7 +123,6 @@ tests:
- mtl
- primitive
- stm
- template-haskell
- text
- unison-core1
- unison-hash
Expand Down
6 changes: 3 additions & 3 deletions unison-runtime/src/Unison/Runtime/Exception.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ instance Exception RuntimeExn

die :: (HasCallStack) => String -> IO a
die = throwIO . PE callStack . P.lit . fromString
{-# INLINEABLE die #-}
{-# INLINE die #-}

dieP :: (HasCallStack) => P.Pretty P.ColorText -> IO a
dieP = throwIO . PE callStack
{-# INLINEABLE dieP #-}
{-# INLINE dieP #-}

exn :: (HasCallStack) => String -> a
exn = throw . PE callStack . P.lit . fromString
{-# INLINEABLE exn #-}
{-# INLINE exn #-}
22 changes: 10 additions & 12 deletions unison-runtime/src/Unison/Runtime/Machine.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import Data.Ord (comparing)
import Data.Sequence qualified as Sq
import Data.Set qualified as S
import Data.Set qualified as Set
import Data.Text (Text)
import Data.Text qualified as DTx
import Data.Text.IO qualified as Tx
import Data.Traversable
Expand Down Expand Up @@ -71,6 +70,7 @@ import Unison.Runtime.ANF as ANF
import Unison.Runtime.ANF qualified as ANF
import Unison.Runtime.Array as PA
import Unison.Runtime.Builtin
import Unison.Runtime.Exception (RuntimeExn (..))
import Unison.Runtime.Foreign
import Unison.Runtime.Foreign.Function
import Unison.Runtime.MCode
Expand Down Expand Up @@ -100,13 +100,6 @@ import Test.Inspection qualified as TI
#endif
{- ORMOLU_ENABLE -}

data RuntimeExn
= PE CallStack (P.Pretty P.ColorText)
| BU [(Reference, Int)] Text Val
deriving (Show)

instance Exception RuntimeExn

-- | A ref storing every currently active thread.
-- This is helpful for cleaning up orphaned threads when the main process
-- completes.
Expand Down Expand Up @@ -676,8 +669,7 @@ eval !env !denv !activeThreads !stk !k r (RMatch i pu br) = do
(ANF.rawTag -> e, ANF.rawTag -> t)
| Just ebs <- EC.lookup e br ->
eval env denv activeThreads stk k r $ selectBranch t ebs
| otherwise ->
error . show . PE undefined . P.lit . fromString $ "eval: unhandled ability request"
| otherwise -> unhandledAbilityRequest
eval !env !denv !activeThreads !stk !k _ (Yield args)
| asize stk > 0,
VArg1 i <- args =
Expand Down Expand Up @@ -710,6 +702,9 @@ eval !_ !_ !_ !_activeThreads !_ _ Exit = pure ()
eval !_ !_ !_ !_activeThreads !_ _ (Die s) = die s
{-# NOINLINE eval #-}

unhandledAbilityRequest :: (HasCallStack) => IO a
unhandledAbilityRequest = error . show . PE callStack . P.lit . fromString $ "eval: unhandled ability request"

forkEval :: CCache -> ActiveThreads -> Val -> IO ThreadId
forkEval env activeThreads clo =
do
Expand Down Expand Up @@ -2560,7 +2555,7 @@ die s = do
-- fail to unbox it, possibly because it can't unbox it when it's strictly a type application.
-- For whatever reason, this seems to fix it while still allowing us to throw exceptions in IO
-- like we prefer.
pure $ error "unreachable"
error "unreachable"
{-# INLINE die #-}

{- ORMOLU_DISABLE -}
Expand All @@ -2569,6 +2564,9 @@ die s = do
-- trigger the worker/wrapper optimization and unbox it fully, and if it fails to do so, we want to
-- know about it.
--
-- Note: this must remain in this module, it can't be moved to a testing module, this is a requirement of the inspection
-- testing library.
--
-- Note: We _must_ check 'eval0' instead of 'eval' here because if you simply check 'eval', you'll be
-- testing the 'wrapper' part of the worker/wrapper, which will always mention the 'Stack' object as part of its
-- unwrapping, and since there's no way to refer to the generated wrapper directly, we instead refer to 'eval0'
Expand All @@ -2578,12 +2576,12 @@ die s = do
--
-- If this test starts failing, here are some things you can check.
--
-- 1. Did you manually
-- 1. Are 'Stack's being passed to dynamic functions? If so, try changing those functions to take an 'XStack' instead,
-- and manually unpack/pack the 'Stack' where necessary.
-- 2. Are there calls to 'die' or 'throwIO' or something similar in which a fully polymorphic type variable is being
-- specialized to 'Stack'? Sometimes this trips up the optimization, you can try using an 'error' instead, or even
-- following the 'throwIO' with a useless call to @error "unreachable"@, this seems to help for some reason.
-- See this page for more info on precise exceptions: https://gitlab.haskell.org/ghc/ghc/-/wikis/exceptions/precise-exceptions
--
-- Best of luck!
TI.inspect $ 'eval0 `TI.hasNoType` ''Stack
Expand Down
1 change: 0 additions & 1 deletion unison-runtime/unison-runtime.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ test-suite runtime-tests
, mtl
, primitive
, stm
, template-haskell
, text
, unison-core1
, unison-hash
Expand Down

0 comments on commit cc68b25

Please sign in to comment.