Skip to content

Commit

Permalink
Merge pull request #1260 from GaloisInc/1259-remove-unused-monoids
Browse files Browse the repository at this point in the history
G/C unused Monoid and Semigroup instances in crucible-mir
  • Loading branch information
sauclovian-g authored Oct 21, 2024
2 parents eb6bd6f + cb53598 commit 2fb1c26
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 37 deletions.
10 changes: 10 additions & 0 deletions crucible-mir/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# next -- TBA

* The calling sequence of ```translateMIR``` has changed: the first argument,
which should always have been passed as ```mempty```, has been removed.
This will require adjustments in any downstream callers.
* The corresponding implicit argument in the ```Pass``` type has been removed.
* The Semigroup and Monoid instances for Collection, CollectionState, and
RustModule have been removed. It is not expected that there are any
downstream users.

# 0.3 -- 2024-08-30

* Implement byte-to-char casts.
Expand Down
13 changes: 0 additions & 13 deletions crucible-mir/src/Mir/Generator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -395,19 +395,6 @@ $(return [])

-- ** Operations and instances

instance Semigroup RustModule where
(RustModule cs1 cm1 ex1) <> (RustModule cs2 cm2 ex2) =
RustModule (cs1 <> cs2) (cm1 <> cm2) (ex1 <> ex2)
instance Monoid RustModule where
mempty = RustModule mempty mempty mempty

instance Semigroup CollectionState where
(CollectionState hm1 vm1 sm1 dm1 chm1 col1) <> (CollectionState hm2 vm2 sm2 dm2 chm2 col2) =
(CollectionState (hm1 <> hm2) (vm1 <> vm2) (sm1 <> sm2) (dm1 <> dm2) (Map.unionWith (<>) chm1 chm2) (col1 <> col2))
instance Monoid CollectionState where
mempty = CollectionState mempty mempty mempty mempty mempty mempty


instance Show (MirExp s) where
show (MirExp tr e) = (show e) ++ ": " ++ (show tr)

Expand Down
12 changes: 0 additions & 12 deletions crucible-mir/src/Mir/Mir.hs
Original file line number Diff line number Diff line change
Expand Up @@ -585,18 +585,6 @@ makeLenses ''Instance
makeLenses ''NamedTy
makeWrapped ''Substs

--------------------------------------------------------------------------------------
-- Other instances for ADT types
--------------------------------------------------------------------------------------

instance Semigroup Collection where
(Collection f1 a1 a1' t1 s1 v1 n1 tys1 r1) <> (Collection f2 a2 a2' t2 s2 v2 n2 tys2 r2) =
Collection (f1 <> f2) (a1 <> a2) (a1' <> a2') (t1 <> t2) (s1 <> s2) (v1 <> v2) (n1 <> n2) (tys1 <> tys2) (r1 <> r2)
instance Monoid Collection where
mempty = Collection mempty mempty mempty mempty mempty mempty mempty mempty mempty



--------------------------------------------------------------------------------------
--- aux functions ---
--------------------------------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions crucible-mir/src/Mir/ParseTranslate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ uninternMir col = uninternTys unintern (col { _namedTys = mempty })

-- | Translate a MIR collection to Crucible
translateMIR :: (HasCallStack, ?debug::Int, ?assertFalseOnError::Bool, ?printCrucible::Bool)
=> CollectionState -> Collection -> C.HandleAllocator -> IO RustModule
translateMIR lib col halloc =
=> Collection -> C.HandleAllocator -> IO RustModule
translateMIR col halloc =
let ?customOps = Mir.customOps in
let col0 = let ?mirLib = lib^.collection in rewriteCollection col
in let ?libCS = lib in transCollection col0 halloc
let col0 = rewriteCollection col
in transCollection col0 halloc
2 changes: 1 addition & 1 deletion crucible-mir/src/Mir/Pass.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import Mir.Pass.AllocateEnum ( passAllocateEnum )

import Debug.Trace

type Pass = (?debug::Int, ?mirLib::Collection, HasCallStack) => Collection -> Collection
type Pass = (?debug::Int, HasCallStack) => Collection -> Collection

--------------------------------------------------------------------------------------
infixl 0 |>
Expand Down
4 changes: 2 additions & 2 deletions crucible-mir/src/Mir/Pass/AllocateEnum.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ and replace them with a single aggregate assignment



passAllocateEnum :: (HasCallStack, ?debug::Int, ?mirLib::Collection) => Collection -> Collection
passAllocateEnum :: (HasCallStack, ?debug::Int) => Collection -> Collection
passAllocateEnum col =
let ?col = ?mirLib <> col in
let ?col = col in
col & functions %~ fmap (& fbody %~ mblocks %~ map pcr)


Expand Down
8 changes: 4 additions & 4 deletions crucible-mir/src/Mir/Trans.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2249,7 +2249,7 @@ mkCrateHashesMap
-- | transCollection: translate a MIR collection
transCollection ::
(HasCallStack, ?debug::Int, ?assertFalseOnError::Bool,
?libCS::CollectionState, ?customOps::CustomOpMap,
?customOps::CustomOpMap,
?printCrucible::Bool)
=> M.Collection
-> FH.HandleAllocator
Expand Down Expand Up @@ -2286,14 +2286,14 @@ transCollection col halloc = do
colState = CollectionState hmap vm sm dm chm col

-- translate all of the functions
fnInfo <- mapM (stToIO . transDefine (?libCS <> colState)) (Map.elems (col^.M.functions))
fnInfo <- mapM (stToIO . transDefine colState) (Map.elems (col^.M.functions))
let pairs1 = [(name, cfg) | (name, cfg, _) <- fnInfo]
let transInfo = Map.fromList [(name, fti) | (name, _, fti) <- fnInfo]
pairs2 <- mapM (stToIO . transVtable (?libCS <> colState)) (Map.elems (col^.M.vtables))
pairs2 <- mapM (stToIO . transVtable colState) (Map.elems (col^.M.vtables))

pairs3 <- Maybe.catMaybes <$> mapM (\intr -> case intr^.M.intrInst of
Instance (IkVirtual dynTraitName methodIndex) methodId _substs ->
stToIO $ Just <$> transVirtCall (?libCS <> colState)
stToIO $ Just <$> transVirtCall colState
(intr^.M.intrName) methodId dynTraitName methodIndex
_ -> return Nothing) (Map.elems (col ^. M.intrinsics))

Expand Down
2 changes: 1 addition & 1 deletion crux-mir/src/Mir/Language.hs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ runTestsWithExtraOverrides bindExtra (cruxOpts, mirOpts) = do

-- Translate to crucible
halloc <- C.newHandleAllocator
mir <- translateMIR mempty col halloc
mir <- translateMIR col halloc

C.AnyCFG staticInitCfg <- transStatics (mir^.rmCS) halloc
let hi = C.cfgHandle staticInitCfg
Expand Down

0 comments on commit 2fb1c26

Please sign in to comment.