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

HOTFIX: restore subsort injections removed by LLVM #452

Merged
Merged
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
28 changes: 22 additions & 6 deletions library/Booster/LLVM.hs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
{- |
Copyright : (c) Runtime Verification, 2023
License : BSD-3-Clause
-}
module Booster.LLVM (simplifyBool, simplifyTerm) where

import Control.Monad.IO.Class (MonadIO (..))
import Data.Binary.Get
import Data.ByteString (fromStrict)
import Data.Map qualified as Map
import Data.Set qualified as Set
import System.IO.Unsafe (unsafePerformIO)

import Booster.Definition.Base
import Booster.LLVM.Internal qualified as Internal
import Booster.Pattern.Base
import Booster.Pattern.Binary
import Booster.Pattern.Util
import Booster.Trace qualified as Trace

simplifyBool :: Internal.API -> Term -> Bool
Expand All @@ -32,5 +31,22 @@ simplifyTerm api def trm sort = unsafePerformIO $ Internal.runLLVM api $ do
binary <- liftIO $ kore.simplify trmPtr sortPtr
liftIO kore.collect
Trace.traceIO $ Internal.LlvmVar (Internal.somePtr trmPtr) trm
Trace.timeIO "LLVM.simplifyTerm.decodeTerm" $
pure (runGet (decodeTerm def) (fromStrict binary))
-- strip away the custom injection added by the LLVM backend
Trace.timeIO "LLVM.simplifyTerm.decodeTerm" $ case runGet (decodeTerm def) (fromStrict binary) of
result
| sortOfTerm result == sort ->
pure result
| newSort@(SortApp name _) <- sortOfTerm result
, Set.member name subsorts ->
pure $ Injection newSort sort result
| otherwise -> do
liftIO . putStrLn $
"[Error] LLVM simplification returned sort "
<> show (sortOfTerm result)
<> ". Expected sort "
<> show sort
pure trm
where
sortName (SortApp name _) = name
sortName (SortVar name) = name
subsorts = maybe Set.empty snd $ Map.lookup (sortName sort) def.sorts