Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove mutex around LLVM calls from booster #4087

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions booster/library/Booster/LLVM/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ module Booster.LLVM.Internal (
LlvmError (..),
) where

import Control.Concurrent.MVar (MVar, newMVar, withMVar)
import Control.Exception (IOException)
import Control.Monad (foldM, forM_, void, (>=>))
import Control.Monad.Catch (MonadCatch, MonadMask, MonadThrow, catch)
Expand Down Expand Up @@ -104,21 +103,19 @@ data API = API
, simplifyBool :: KorePatternPtr -> IO (Either LlvmError Bool)
, simplify :: KorePatternPtr -> KoreSortPtr -> IO (Either LlvmError ByteString)
, collect :: IO ()
, mutex :: MVar ()
}

newtype LLVM a = LLVM (ReaderT API IO a)
deriving newtype (Functor, Applicative, Monad, MonadIO, MonadThrow, MonadCatch, MonadMask)

{- | Uses dlopen to load a .so/.dylib C library at runtime. For doucmentation of flags such as `RTL_LAZY`, consult e.g.
{- | Uses dlopen to load a .so/.dylib C library at runtime. For documentation of flags such as `RTL_LAZY`, consult e.g.
https://man7.org/linux/man-pages/man3/dlopen.3.html
-}
withDLib :: FilePath -> (Linker.DL -> IO a) -> IO a
withDLib dlib = Linker.withDL dlib [Linker.RTLD_LAZY]

runLLVM :: API -> LLVM a -> IO a
runLLVM api (LLVM m) =
withMVar api.mutex $ const $ runReaderT m api
runLLVM api (LLVM m) = runReaderT m api

mkAPI :: Linker.DL -> IO API
mkAPI dlib = flip runReaderT dlib $ do
Expand Down Expand Up @@ -282,8 +279,7 @@ mkAPI dlib = flip runReaderT dlib $ do
stderr
"[Warn] Using an LLVM backend compiled with --llvm-mutable-bytes (unsound byte array semantics)"

mutex <- liftIO $ newMVar ()
pure API{patt, symbol, sort, simplifyBool, simplify, collect, mutex}
pure API{patt, symbol, sort, simplifyBool, simplify, collect}

ask :: LLVM API
ask = LLVM Reader.ask
Expand Down
2 changes: 1 addition & 1 deletion scripts/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
else:
minchange = 0.035

testname = re.compile(r'.*\[(?P<name>.*)\]$')
testname = re.compile(r'^[^\[]*\[(?P<name>.*)\]$')

def readName(input):
r = testname.match(input)
Expand Down
3 changes: 2 additions & 1 deletion scripts/performance-tests-kontrol.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ sed -i'' -e "s|'forge', 'build'|'forge', 'build', '--no-auto-detect'|g" src/kont
sed -i'' -e "s|'forge', 'build'|'forge', 'build', '--no-auto-detect'|g" src/tests/utils.py
sed -i'' -e "s|'forge', 'build'|'forge', 'build', '--no-auto-detect'|g" src/tests/integration/conftest.py
# update the lock file to keep poetry from complaining
poetry lock --no-update
# option `--no-update` was inverted to `--regenerate` in poetry-2.0.0
poetry lock --no-update || poetry lock

feature_shell() {
GC_DONT_GC=1 nix develop . --extra-experimental-features 'nix-command flakes' --override-input kevm/k-framework/haskell-backend $SCRIPT_DIR/../ --ignore-environment --command bash -c "$1"
Expand Down
Loading