Skip to content

Commit

Permalink
support data-default-0.8.0.0 (#1376)
Browse files Browse the repository at this point in the history
* support data-default-0.8.0.0

* some more meaningful default values

* Apply suggestions from code review

Co-authored-by: John Wiegley <[email protected]>

* revert previous change

---------

Co-authored-by: John Wiegley <[email protected]>
  • Loading branch information
larskuhtz and jwiegley authored Oct 25, 2024
1 parent f5980d1 commit ef32c9c
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Pact/Bench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ main :: IO ()
main = do
-- uncomment below to see if "-N" is working, important for file perf log
-- print =<< getNumCapabilities
!fperf <- if doPerf /= None then mkFilePerf "pact-bench-perf" else def
!fperf <- if doPerf /= None then mkFilePerf "pact-bench-perf" else pure def
let !dbPerf = if doPerf == Db || doPerf == All then fperf else def
!interpPerf = if doPerf == Interp || doPerf == All then fperf else def
!pub <- eitherDie "pub" $ parseB16TextOnly pk
Expand Down
2 changes: 1 addition & 1 deletion src/Pact/Runtime/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ stripTermInfo = stripTerm' stripNameInfo
stripArgInfo f (Arg an argtyp _info) =
Arg an (stripTypeInfo f argtyp) def
stripMetaInfo (Meta docs model) =
Meta docs (fmap def <$> model)
Meta docs (fmap (const def) <$> model)
stripAppInfo f (App af args _info) =
App (stripTerm' f af) (stripTerm' f <$> args) def
stripStepInfo f = \case
Expand Down
7 changes: 5 additions & 2 deletions src/Pact/Types/Capability.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module Pact.Types.Capability
, UserManagedCap(..), umcManagedValue, umcManageParamIndex, umcManageParamName, umcMgrFun
, AutoManagedCap(..), amcActive
, decomposeManaged, decomposeManaged', matchManaged
, Capabilities(..), capStack, capManaged, capModuleAdmin, capAutonomous
, Capabilities(..), capStack, capManaged, capModuleAdmin, capAutonomous, emptyCapabilities
, CapScope(..)
, CapSlot(..), csCap, csComposed, csScope
) where
Expand Down Expand Up @@ -191,9 +191,12 @@ data Capabilities = Capabilities
}
deriving (Eq,Show,Generic)

instance Default Capabilities where def = Capabilities [] mempty mempty mempty
instance Default Capabilities where def = emptyCapabilities
instance NFData Capabilities

emptyCapabilities :: Capabilities
emptyCapabilities = Capabilities mempty mempty mempty mempty

makeLenses ''ManagedCapability
makeLenses ''Capabilities
makeLenses ''CapSlot
Expand Down
12 changes: 10 additions & 2 deletions src/Pact/Types/ChainMeta.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ module Pact.Types.ChainMeta
, pmAddress, pmChainId, pmSender, pmGasLimit, pmGasPrice, pmTTL, pmCreationTime
, pdPublicMeta, pdBlockHeight, pdBlockTime, pdPrevBlockHash
, getCurrentCreationTime
, noPublicMeta
, noPublicData
) where


Expand Down Expand Up @@ -149,7 +151,10 @@ data PublicMeta = PublicMeta
} deriving (Eq, Show, Generic)
makeLenses ''PublicMeta

instance Default PublicMeta where def = PublicMeta "" "" 0 0 0 0
instance Default PublicMeta where def = noPublicMeta

noPublicMeta :: PublicMeta
noPublicMeta = PublicMeta "" mempty 0 0 0 0

instance Arbitrary PublicMeta where
arbitrary = PublicMeta
Expand Down Expand Up @@ -224,7 +229,10 @@ instance J.Encode PublicData where
{-# INLINABLE build #-}

instance FromJSON PublicData where parseJSON = lensyParseJSON 3
instance Default PublicData where def = PublicData def def def def
instance Default PublicData where def = noPublicData

noPublicData :: PublicData
noPublicData = PublicData noPublicMeta 0 0 mempty

instance Arbitrary PublicData where
arbitrary = PublicData
Expand Down
13 changes: 10 additions & 3 deletions src/Pact/Types/Info.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
module Pact.Types.Info
(
Parsed(..),
noParsed,
Code(..),
Info(..),
mkInfo,
renderInfo,
renderParsed,
HasInfo(..)
HasInfo(..),
noInfo
) where


Expand Down Expand Up @@ -81,9 +83,11 @@ instance Arbitrary Parsed where
-- The parser always assumes that the last to numbers are zero
, Directed <$> genFilename <*> genPositiveInt64 <*> genPositiveInt64 <*> pure 0 <*> pure 0 ]
instance NFData Parsed
instance Default Parsed where def = Parsed mempty 0
instance Default Parsed where def = noParsed
instance Pretty Parsed where pretty = pretty . _pDelta

noParsed :: Parsed
noParsed = Parsed mempty 0

newtype Code = Code { _unCode :: Text }
deriving (Eq,Ord,Generic)
Expand All @@ -110,7 +114,10 @@ instance Show Info where
show (Info Nothing) = ""
show (Info (Just (r,_d))) = renderCompactString r

instance Default Info where def = Info Nothing
instance Default Info where def = noInfo

noInfo :: Info
noInfo = Info Nothing

-- | Charge zero for Info to avoid quadratic blowup (i.e. for modules)
instance SizeOf Info where
Expand Down
21 changes: 15 additions & 6 deletions src/Pact/Types/Runtime.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ module Pact.Types.Runtime
eeAdvice, eeWarnings, eeSigCapBypass,
toPactId,
Purity(..),
RefState(..),rsLoaded,rsLoadedModules,rsNamespace,rsQualifiedDeps,
EvalState(..),evalRefs,evalCallStack,evalPactExec,
RefState(..),rsLoaded,rsLoadedModules,rsNamespace,rsQualifiedDeps,emptyRefState,
EvalState(..),evalRefs,evalCallStack,evalPactExec,emptyEvalState,
evalCapabilities,evalLogGas,evalEvents,evalUserCapabilitiesBeingEvaluated,
Eval(..),runEval,runEval',catchesPactError,
call,method,
Expand All @@ -45,7 +45,7 @@ module Pact.Types.Runtime
NamespacePolicy(..),
permissiveNamespacePolicy,
ExecutionConfig(..),ExecutionFlag(..),ecFlags,isExecutionFlagSet,flagRep,flagReps,
mkExecutionConfig,
mkExecutionConfig,emptyExecutionConfig,
ifExecutionFlagSet,ifExecutionFlagSet',
whenExecutionFlagSet, unlessExecutionFlagSet,
emitPactWarning,
Expand Down Expand Up @@ -242,10 +242,13 @@ newtype ExecutionConfig = ExecutionConfig
deriving (FromJSON)

makeLenses ''ExecutionConfig
instance Default ExecutionConfig where def = ExecutionConfig def
instance Default ExecutionConfig where def = emptyExecutionConfig
instance Pretty ExecutionConfig where
pretty = pretty . S.toList . _ecFlags

emptyExecutionConfig :: ExecutionConfig
emptyExecutionConfig = ExecutionConfig mempty

instance Arbitrary ExecutionConfig where
arbitrary = ExecutionConfig <$> arbitrary

Expand Down Expand Up @@ -323,7 +326,10 @@ data RefState = RefState {

makeLenses ''RefState
instance NFData RefState
instance Default RefState where def = RefState HM.empty HM.empty Nothing HM.empty
instance Default RefState where def = emptyRefState

emptyRefState :: RefState
emptyRefState = RefState mempty mempty Nothing mempty

data PactEvent = PactEvent
{ _eventName :: !Text
Expand Down Expand Up @@ -373,7 +379,10 @@ data EvalState = EvalState {
} deriving (Show, Generic)
makeLenses ''EvalState
instance NFData EvalState
instance Default EvalState where def = EvalState def def def def def def def
instance Default EvalState where def = emptyEvalState

emptyEvalState :: EvalState
emptyEvalState = EvalState emptyRefState mempty Nothing emptyCapabilities mempty mempty mempty

-- | Interpreter monad, parameterized over back-end MVar state type.
newtype Eval e a =
Expand Down

0 comments on commit ef32c9c

Please sign in to comment.