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

pact warnings #1129

Merged
merged 1 commit into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions src-ghc/Pact/Interpreter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -227,14 +229,15 @@ 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
-- output uses lenient conversion
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)
Expand Down
4 changes: 2 additions & 2 deletions src/Pact/Repl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/Pact/Types/Runtime.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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.
--
Expand Down