Skip to content

Commit 1027a1f

Browse files
authored
Introduce StableHashMap to support hashable-1.5.0.0 (#1378)
* Introduce StableHashMap to support hashable-1.5.0.0 * add test cases for StableHashable * tests for StableHashMap
1 parent 058da31 commit 1027a1f

27 files changed

+3130
-124
lines changed

pact.cabal

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ library
203203
Pact.Types.Verifier
204204
Pact.Types.Version
205205
Pact.Utils.Servant
206+
Pact.Utils.StableHashMap
206207

207208
other-modules:
208209
Pact.Crypto.WebAuthn.Cose.PublicKey
@@ -448,6 +449,7 @@ test-suite hspec
448449
, directory
449450
, errors
450451
, filepath
452+
, hashable
451453
, hspec
452454
, lens
453455
, mod
@@ -474,6 +476,7 @@ test-suite hspec
474476
Test.Pact.Native.Pairing
475477
Test.Pact.Parse
476478
Test.Pact.Utils.LegacyValue
479+
Test.Pact.Utils.StableHashMap
477480

478481
if flag(build-tool)
479482
cpp-options: -DBUILD_TOOL

src-tool/Pact/Analyze/Check.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ import Pact.Analyze.Translate
106106
import Pact.Analyze.Types
107107
import Pact.Analyze.Util
108108
import Pact.Types.Exp
109+
import qualified Pact.Utils.StableHashMap as SHM
109110

110111
smtConfig :: SBV.SMTConfig
111112
smtConfig = SBV.z3
@@ -766,7 +767,7 @@ parseModuleModelDecl exps = traverse parseDecl exps where
766767

767768
-- | Organize the module's refs by type
768769
moduleRefs :: ModuleData Ref -> ModuleRefs
769-
moduleRefs (ModuleData _ refMap _) = foldl' f noRefs (HM.toList refMap)
770+
moduleRefs (ModuleData _ refMap _) = foldl' f noRefs (SHM.toList refMap)
770771
where
771772
f accum (name, ref) = case ref of
772773
Ref (TDef (Def{_dDefType, _dDefBody}) _) ->
@@ -1137,7 +1138,7 @@ getFunChecks env@(CheckEnv tables consts propDefs moduleData _cs _g de _) refs =
11371138
scopeCheckInterface
11381139
:: Set Text
11391140
-- ^ A set of table, definition and property names in scope
1140-
-> HM.HashMap Text Ref
1141+
-> SHM.StableHashMap Text Ref
11411142
-- ^ The set of refs to check
11421143
-> [ScopeError]
11431144
scopeCheckInterface globalNames refs = refs <&&> \case
@@ -1229,7 +1230,7 @@ verifyModule mDebug de modules moduleData@(ModuleData modDef allRefs _) = runExc
12291230
globalNames = Set.unions $ fmap Set.fromList
12301231
[ fmap _tableName tables
12311232
, HM.keys propDefs
1232-
, HM.keys allRefs
1233+
, SHM.keys allRefs
12331234
]
12341235
scopeErrors = scopeCheckInterface globalNames allRefs
12351236

@@ -1322,7 +1323,7 @@ verifyCheck de moduleData funName check checkType = do
13221323
moduleName = moduleDefName $ moduleData ^. mdModule
13231324
modules = HM.fromList [(moduleName, moduleData)]
13241325
moduleFun :: ModuleData Ref -> Text -> Maybe Ref
1325-
moduleFun ModuleData{..} name = name `HM.lookup` _mdRefMap
1326+
moduleFun ModuleData{..} name = name `SHM.lookup` _mdRefMap
13261327
modRefs = moduleRefs moduleData
13271328

13281329
caps <- moduleCapabilities de [moduleData]

src/Pact/Bench.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import Data.Aeson
2121
import Data.ByteString (ByteString)
2222
import qualified Data.ByteString as BS
2323
import Data.Default
24-
import qualified Data.HashMap.Strict as HM
2524
import qualified Data.Map.Strict as M
2625
import qualified Data.Set as S
2726
import Data.Text (unpack, pack, intercalate)
@@ -60,6 +59,7 @@ import Pact.Types.Capability
6059
import Pact.Runtime.Utils
6160
import Pact.JSON.Legacy.Value
6261
import qualified Pact.JSON.Encode as J
62+
import qualified Pact.Utils.StableHashMap as SHM
6363

6464
-- | Flags for enabling file-based perf bracketing,
6565
-- see 'mkFilePerf' below.
@@ -191,7 +191,7 @@ runPactExec pt msg ss cdata benchMod dbEnv pc = do
191191
e <- set eeAdvice pt <$> setupEvalEnv dbEnv entity Transactional md (versionedNativesRefStore ec)
192192
prodGasEnv permissiveNamespacePolicy noSPVSupport def ec
193193
let s = perfInterpreter pt $ defaultInterpreterState $
194-
maybe id (const . initStateModules . HM.singleton (ModuleName "bench" Nothing)) benchMod
194+
maybe id (const . initStateModules . SHM.singleton (ModuleName "bench" Nothing)) benchMod
195195
(r :: Either SomeException EvalResult) <- try $! evalExec s e pc
196196
r' <- eitherDie ("runPactExec': " ++ msg) $ fmapL show r
197197
return $!! _erOutput r'

src/Pact/Coverage.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import Pact.Types.Pretty
3838
import Pact.Types.Term hiding (App(..),Object(..),Step(..))
3939
import Pact.Types.Typecheck
4040
import Pact.Types.Runtime (ModuleData(..))
41+
import qualified Pact.Utils.StableHashMap as SHM
4142

4243
mkCoverageAdvice :: IO (IORef LcovReport,Advice)
4344
mkCoverageAdvice = newIORef mempty >>= \r -> return (r,Advice $ cover r)
@@ -78,7 +79,7 @@ cover ref i ctx = case _iInfo i of
7879
postModule :: MonadIO m => ModuleData Ref -> m ()
7980
postModule (ModuleData (MDModule _m) modDefs _) = do
8081
((modFuns,modLines),_) <- liftIO $ runTC 0 False $
81-
foldM walkDefs (mempty,mempty) (HM.elems modDefs)
82+
foldM walkDefs (mempty,mempty) (SHM.elems modDefs)
8283
let (fn,_l) = parseInf i
8384
newRep = mkFileLcov fn modFuns mempty modLines
8485
liftIO $ modifyIORef ref (<> newRep)

0 commit comments

Comments
 (0)