diff --git a/src-ghc/Pact/Interpreter.hs b/src-ghc/Pact/Interpreter.hs index e2a20ab34..1327a8692 100644 --- a/src-ghc/Pact/Interpreter.hs +++ b/src-ghc/Pact/Interpreter.hs @@ -128,6 +128,8 @@ data EvalResult = EvalResult -- ^ Details on each gas consumed/charged , _erEvents :: [PactEvent] -- ^ emitted events + , _erWarnings :: S.Set PactWarning + -- ^ emitted warning } deriving (Eq,Show) -- | Execute pact statements. @@ -169,7 +171,7 @@ setupEvalEnv -> IO (EvalEnv e) setupEvalEnv dbEnv ent mode msgData refStore gasEnv np spv pd ec = do gasRef <- newIORef 0 - warnRef <- newIORef [] + warnRef <- newIORef mempty pure EvalEnv { _eeRefStore = refStore , _eeMsgSigs = mkMsgSigs $ mdSigners msgData @@ -227,6 +229,7 @@ interpret runner evalEnv terms = do ((rs,logs,txid),state) <- runEval def evalEnv $ evalTerms runner terms gas <- readIORef (_eeGas evalEnv) + warnings <- readIORef (_eeWarnings evalEnv) let gasLogs = _evalLogGas state pactExec = _evalPactExec state modules = _rsLoadedModules $ _evalRefs state @@ -234,7 +237,7 @@ interpret runner evalEnv terms = do return $! EvalResult terms (map (elideModRefInfo . toPactValueLenient) rs) - logs pactExec gas modules txid gasLogs (_evalEvents state) + logs pactExec gas modules txid gasLogs (_evalEvents state) warnings evalTerms :: Interpreter e -> EvalInput -> Eval e EvalOutput evalTerms interp input = withRollback (start (interpreter interp runInput) >>= end) diff --git a/src/Pact/Repl.hs b/src/Pact/Repl.hs index 360f15f44..744df80bd 100644 --- a/src/Pact/Repl.hs +++ b/src/Pact/Repl.hs @@ -132,7 +132,7 @@ initEvalEnv :: LibState -> IO (EvalEnv LibState) initEvalEnv ls = do mv <- newMVar ls gasRef <- newIORef 0 - warnRef <- newIORef [] + warnRef <- newIORef mempty return $ EvalEnv { _eeRefStore = RefStore nativeDefs , _eeMsgSigs = mempty @@ -248,7 +248,7 @@ pureEval ei e = do wref <- use (rEnv . eeWarnings) warnings <- liftIO $ readIORef wref traverse_ (outStrLn HOut . renderCompactString) warnings - liftIO $ writeIORef wref [] + liftIO $ writeIORef wref mempty doOut ei mode a rEvalState .= es updateForOp ei a diff --git a/src/Pact/Types/Runtime.hs b/src/Pact/Types/Runtime.hs index b467c612f..496aa9af0 100644 --- a/src/Pact/Types/Runtime.hs +++ b/src/Pact/Types/Runtime.hs @@ -74,6 +74,7 @@ import qualified Data.Map.Strict as M import qualified Data.Set as S import Data.String import Data.Text (Text,pack) +import Data.Set(Set) import GHC.Generics (Generic) import Pact.Types.Capability @@ -125,7 +126,7 @@ data PactWarning = DeprecatedNative NativeDefName Text -- | Deprecated overload with help message | DeprecatedOverload NativeDefName Text - deriving (Show) + deriving (Show, Eq, Ord) instance Pretty PactWarning where pretty = \case @@ -246,7 +247,7 @@ data EvalEnv e = EvalEnv { -- | Are we in the repl? If not, ignore info , _eeInRepl :: Bool -- | Warnings ref - , _eeWarnings :: IORef [PactWarning] + , _eeWarnings :: IORef (Set PactWarning) } makeLenses ''EvalEnv @@ -364,7 +365,7 @@ method i f = do emitPactWarning :: PactWarning -> Eval e () emitPactWarning pw = - view eeWarnings >>= \e -> liftIO (modifyIORef' e (pw:)) + view eeWarnings >>= \e -> liftIO (modifyIORef' e (S.insert pw)) -- -- Methods for invoking backend function-record function. --