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

Add Imports + Myriad Bug Fixes #585

Merged
merged 35 commits into from Sep 12, 2019
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
cf1ae0c
update bnf with module guards
emilypi Jul 15, 2019
2d4d211
no more importing interfaces
emilypi Jul 15, 2019
f27997b
disallow module definition name shadowing
emilypi Jul 15, 2019
8495e20
remove stale md
emilypi Jul 15, 2019
a18eca4
remove space
emilypi Jul 15, 2019
9211d1b
undo lensiness
emilypi Jul 15, 2019
0abffe1
found a bug in tc.repl test suite
emilypi Jul 15, 2019
945f51d
disallow native name overlaps
emilypi Jul 16, 2019
99506db
update bench.pact
emilypi Jul 16, 2019
b508446
add same check for interfaces
emilypi Jul 17, 2019
7d185ff
update cabal project
emilypi Jul 17, 2019
abe19a4
hidden imports updates
emilypi Jul 18, 2019
7a3d5df
streamline our gas + name retrievals
emilypi Jul 18, 2019
0068158
updates
emilypi Jul 18, 2019
703c8de
add correct parsing form
emilypi Jul 19, 2019
389f147
remove cruft
emilypi Jul 19, 2019
12932c2
fix installModule + some updates. TODO: track imports when resolving …
emilypi Jul 20, 2019
c0dc0f9
updates, add case for def conflicting with import
emilypi Jul 20, 2019
510ea9a
remove stack spam
emilypi Jul 20, 2019
b9e4ac5
remove test that we decided was ok to have
emilypi Jul 20, 2019
b945fd7
disallow capability imports
emilypi Jul 20, 2019
2dac411
add note, switch back to foldl
emilypi Jul 20, 2019
264bd82
small undo's
emilypi Jul 21, 2019
dc43979
json instance for 'Use'
emilypi Jul 21, 2019
fa3bdd5
update docs
emilypi Jul 29, 2019
1c03b85
restrict validateImports to just functions, constants, schema
emilypi Jul 29, 2019
3bdcfef
small switchups to the API
emilypi Jul 30, 2019
cee7b33
add additional test for table symbols
emilypi Jul 30, 2019
c120470
Merge branch 'master' into emily/bugfix-571
emilypi Aug 1, 2019
927cdb5
Update tests/pact/tc.repl
emilypi Sep 12, 2019
c0859c3
Update tests/pact/tc.repl
emilypi Sep 12, 2019
21ffab6
address stuart's comments
emilypi Sep 12, 2019
f63cce3
Merge branch 'emily/bugfix-571' of github.com:kadena-io/pact into emi…
emilypi Sep 12, 2019
68705a1
bump version to 3.3.0
emilypi Sep 12, 2019
cf945b0
Merge branch 'master' into emily/bugfix-571
emilypi Sep 12, 2019
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

updates

  • Loading branch information
emilypi committed Jul 18, 2019
commit 00681582e5b9fe232adff9a3b75cd342a200dfef

This file was deleted.

@@ -554,7 +554,8 @@ useForm = do
h <- optional hash'
l <- optional $ withList' Brackets (str `sepBy` sep Comma)

let u = Use mn h (fromMaybe [] l) i
let v = fmap V.fromList l
let u = Use mn h v i
-- this is the one place module may not be present, use traversal
psUser . csModule . _Just . msImports %= (u:)
return $ TUse u i
@@ -305,7 +305,7 @@ toPersistDirect' t = case toPersistDirect t of


evalUse :: Use -> Eval e ()
evalUse (Use mn h _ i) = do
evalUse (Use mn h is i) = do
mm <- resolveModule i mn
case mm of
Nothing -> evalError i $ "Module " <> pretty mn <> " not found"
@@ -325,6 +325,7 @@ evalUse (Use mn h _ i) = do
$ "Interfaces should not have associated hashes: "
<> pretty (_interfaceName i')

evalRefs . rsImports %= mappend is
installModule False md

mangleDefs :: ModuleName -> Term Name -> Term Name
@@ -338,10 +339,14 @@ mangleDefs mn term = modifyMn term
_ -> id

-- | Make table of module definitions for storage in namespace/RefStore.
loadModule :: Module (Term Name) -> Scope n Term Name -> Info -> Gas
-> Eval e (Gas,ModuleData Ref)
loadModule
:: Module (Term Name)
-> Scope n Term Name
-> Info
-> Gas
-> Eval e (Gas,ModuleData Ref)
loadModule m@Module {} bod1 mi g0 = do
(g1,mdefs) <- withGas g0 (GModuleMember $ MDModule m) bod1 $ \t -> case t of
(g1,mdefs) <- withNames g0 (GModuleMember $ MDModule m) bod1 $ \t -> case t of
TDef d _ -> return $ Just $ asString (_dDefName d)
TConst a _ _ _ _ -> return $ Just $ _aName a
TSchema n _ _ _ _ -> return $ Just $ asString n
@@ -356,24 +361,14 @@ loadModule m@Module {} bod1 mi g0 = do
installModule True md
return (g1,md)

resolveGovernance
:: HM.HashMap Text Ref
-> Module (Term Name)
-> Eval e (ModuleDef (Def Ref))
resolveGovernance solvedDefs m' = fmap MDModule $ forM m' $ \g -> case g of
TVar (Name n _) _ -> case HM.lookup n solvedDefs of
Just r -> case r of
(Ref (TDef govDef _)) -> case _dDefType govDef of
Defcap -> return govDef
_ -> evalError (_tInfo g) "Invalid module governance, must be defcap"
_ -> evalError (_tInfo g) "Invalid module governance, should be def ref"
Nothing -> evalError (_tInfo g) "Unknown module governance reference"
_ -> evalError (_tInfo g) "Invalid module governance, should be var"

loadInterface :: Interface -> Scope n Term Name -> Info -> Gas
-> Eval e (Gas,ModuleData Ref)
loadInterface
:: Interface
-> Scope n Term Name
-> Info
-> Gas
-> Eval e (Gas,ModuleData Ref)
loadInterface i@Interface{..} body info gas0 = do
(gas1,idefs) <- withGas gas0 (GModuleMember $ MDInterface i) body $ \t -> case t of
(gas1,idefs) <- withNames gas0 (GModuleMember $ MDInterface i) body $ \t -> case t of
TDef d _ -> return $ Just $ asString (_dDefName d)
TConst a _ _ _ _ -> return $ Just $ _aName a
TSchema n _ _ _ _ -> return $ Just $ asString n
@@ -388,7 +383,7 @@ loadInterface i@Interface{..} body info gas0 = do
-- | Retrieve map of definition names to their corresponding terms
-- and compute their gas value
--
withGas
withNames
:: Gas
-- ^ initial gas value
-> GasArgs
@@ -398,7 +393,7 @@ withGas
-> (Term Name -> Eval e (Maybe Text))
-- ^ function extracting definition names
-> Eval e (Gas, HM.HashMap Text (Term Name))
withGas g0 args body k = case instantiate' body of
withNames g0 args body k = case instantiate' body of
TList bd _ _ -> foldM go (g0, mempty) bd
t -> evalError' t $ "malformed declaration"
where
@@ -408,13 +403,33 @@ withGas g0 args body k = case instantiate' body of
Nothing -> return (g, ds)
Just dn -> do
rs <- view $ eeRefStore . rsNatives
is <- use $ evalRefs . rsImports
when (V.elem dn is) $
evalError' t $ "definition is not in the list of explicit imports" <> pretty dn
-- disallow native overlap
when (isJust $ HM.lookup (Name dn def) rs) $
evalError' t $ "definitions cannot overlap with native names: " <> pretty dn
-- disallow conflicting members
when (isJust $ HM.lookup dn ds) $
evalError' t $ "definition name conflict: " <> pretty dn

g' <- computeGas (Left (_tInfo t,dn)) args
return (g + g',HM.insert dn t ds)

resolveGovernance
:: HM.HashMap Text Ref
-> Module (Term Name)
-> Eval e (ModuleDef (Def Ref))
resolveGovernance solvedDefs m' = fmap MDModule $ forM m' $ \g -> case g of
TVar (Name n _) _ -> case HM.lookup n solvedDefs of
Just r -> case r of
Ref (TDef govDef _) -> case _dDefType govDef of
Defcap -> return govDef
_ -> evalError (_tInfo g) "Invalid module governance, must be defcap"
_ -> evalError (_tInfo g) "Invalid module governance, should be def ref"
Nothing -> evalError (_tInfo g) "Unknown module governance reference"
_ -> evalError (_tInfo g) "Invalid module governance, should be var"


-- | Definitions are transformed such that all free variables are resolved either to
-- an existing ref in the refstore/namespace ('Right Ref'), or a symbol that must
@@ -426,15 +441,19 @@ withGas g0 args body k = case instantiate' body of
evaluateDefs :: Info -> HM.HashMap Text (Term Name) -> Eval e (HM.HashMap Text Ref)
evaluateDefs info defs = do
cs <- traverseGraph defs
sortedDefs <- forM cs $ \c ->
case c of
AcyclicSCC v -> return v
CyclicSCC vs -> evalError (if null vs then info else _tInfo $ view _1 $ head vs) $
"Recursion detected: " <>
prettyList (vs & traverse . _1 %~ fmap mkSomeDoc
& traverse . _3 %~ (SomeDoc . prettyList))
sortedDefs <- forM cs $ \c -> case c of
AcyclicSCC v -> return v
CyclicSCC vs -> do
let i = if null vs then info else _tInfo $ view _1 $ head vs
pl = vs
& traverse . _1 %~ fmap mkSomeDoc
This conversation was marked as resolved by emilypi

This comment has been minimized.

Copy link
@slpopejoy

slpopejoy Sep 12, 2019

Contributor

if there are changes to this file let's conform this lensy mess

This comment has been minimized.

Copy link
@emilypi

emilypi Sep 12, 2019

Author Collaborator

Conformed to the style guide

& traverse . _3 %~ (SomeDoc . prettyList)

evalError i $ "Recursion detected: " <> prettyList pl

let dresolve ds (d,dn,_) = HM.insert dn (Ref $ unify ds <$> d) ds
unifiedDefs = foldl dresolve HM.empty sortedDefs

traverse (runSysOnly . evalConsts) unifiedDefs

mkSomeDoc :: (Pretty a, Pretty b) => Either a b -> SomeDoc
@@ -836,7 +855,7 @@ installModule updated md = do
msg :: Doc -> Term n
msg = toTerm . renderCompactText'

enscope :: Term Name -> Eval e (Term Ref)
enscope :: Term Name -> Eval e (Term Ref)
enscope t = instantiate' <$> (resolveFreeVars (_tInfo t) . abstract (const Nothing) $ t)

instantiate' :: Scope n Term a -> Term a
@@ -26,7 +26,7 @@ module Pact.Types.Runtime
toPactId,
Purity(..),PureSysOnly,PureReadOnly,EnvSysOnly(..),EnvReadOnly(..),mkSysOnlyEnv,mkReadOnlyEnv,
StackFrame(..),sfName,sfLoc,sfApp,
RefState(..),rsLoaded,rsLoadedModules,rsNamespace,
RefState(..),rsLoaded,rsLoadedModules,rsNamespace,rsImports,
EvalState(..),evalRefs,evalCallStack,evalPactExec,evalGas,evalCapabilities,
Eval(..),runEval,runEval',catchesPactError,
call,method,
@@ -58,6 +58,7 @@ import qualified Data.Map.Strict as M
import qualified Data.Set as S
import Data.String
import Data.Text (Text, unpack)
import Data.Vector (Vector)

import GHC.Generics

@@ -222,9 +223,11 @@ data RefState = RefState {
, _rsLoadedModules :: HM.HashMap ModuleName (ModuleData Ref, Bool)
-- | Current Namespace
, _rsNamespace :: Maybe Namespace
-- | explicit imports
, _rsImports :: !(Maybe (Vector Text))
} deriving (Eq,Show)
makeLenses ''RefState
instance Default RefState where def = RefState HM.empty HM.empty Nothing
instance Default RefState where def = RefState HM.empty HM.empty Nothing mempty

data Capabilities = Capabilities
{ _capGranted :: [Capability]
@@ -516,7 +516,7 @@ instance Ord Name where
data Use = Use
{ _uModuleName :: !ModuleName
, _uModuleHash :: !(Maybe ModuleHash)
, _uHiddenImports :: [Text]
, _uHiddenImports :: !(Maybe (Vector Text))
, _uInfo :: !Info
} deriving (Eq, Show, Generic)

@@ -618,7 +618,6 @@ instance FromJSON Interface where parseJSON = lensyParseJSON 10

instance NFData Interface


data ModuleDef g
= MDModule !(Module g)
| MDInterface !Interface

This file was deleted.

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.