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

Use custom version of timely, improve rule formatting. #862

Merged
merged 2 commits into from
Dec 12, 2020
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
6 changes: 4 additions & 2 deletions rust/template/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ abomonation = "0.7"
time = { version = "0.2", features = ["serde"] }
ordered-float = { version = "2.0.0", features = ["serde"] }
cpuprofiler = { version = "0.0", optional = true }
differential-dataflow = "0.11.0"
#differential-dataflow = "0.11.0"
differential-dataflow = { git = "https://github.com/ddlog-dev/differential-dataflow", branch = "ddlog-1" }
#timely = "0.11"
timely = { git = "https://github.com/ddlog-dev/timely-dataflow", branch = "ddlog-1" }
fnv = "1.0.2"
once_cell = "1.4.1"
libc = "0.2"
Expand All @@ -42,7 +45,6 @@ num = { version = "0.3", features = ["serde"] }
rustop = { version = "1.0.2", optional = true }
serde = { version = "1.0", features = ["derive"] }
erased-serde = "0.3"
timely = "0.11"

# FlatBuffers dependency enabled by the `flatbuf` feature.
# flatbuffers crate version must be in sync with the flatc compiler and Java
Expand Down
7 changes: 5 additions & 2 deletions rust/template/differential_datalog/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ nested_ts_32 = []
c_api = []

[dependencies]
differential-dataflow = "0.11.0"
#differential-dataflow = "0.11.0"
differential-dataflow = { git = "https://github.com/ddlog-dev/differential-dataflow", branch = "ddlog-1" }
#timely = "0.11"
timely = { git = "https://github.com/ddlog-dev/timely-dataflow", branch = "ddlog-1" }

abomonation = "0.7"
ordered-float = { version = "2.0.0", features = ["serde"] }
fnv = "1.0.2"
timely = "0.11"
libc = "0.2"
csv = "1.1"
num = { version = "0.3", features = ["serde"] }
Expand Down
6 changes: 4 additions & 2 deletions rust/template/differential_datalog_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ version = "0.1.0"
edition = "2018"

[dependencies]
differential-dataflow = "0.11.0"
# differential-dataflow = "0.11.0"
differential-dataflow = { git = "https://github.com/ddlog-dev/differential-dataflow", branch = "ddlog-1" }
abomonation = "0.7"
fnv = "1.0.2"
timely = "0.11"
# timely = "0.11"
timely = { git = "https://github.com/ddlog-dev/timely-dataflow", branch = "ddlog-1" }
serde = { version = "1.0", features = ["derive"] }
erased-serde = "0.3"
differential_datalog = { path = "../differential_datalog" }
Expand Down
12 changes: 7 additions & 5 deletions src/Language/DifferentialDatalog/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -671,8 +671,10 @@ mkCargoToml rs_code crate =
"serde = { version = \"1.0\", features = [\"derive\"] }" $$
"num = \"0.3\"" $$
"erased-serde = \"0.3\"" $$
"differential-dataflow = \"0.11.0\"" $$
"timely = \"0.11\"" $$
--"differential-dataflow = \"0.11.0\"" $$
--"timely = \"0.11\"" $$
"differential-dataflow = { git = \"https://github.com/ddlog-dev/differential-dataflow\", branch = \"ddlog-1\" }" $$
"timely = { git = \"https://github.com/ddlog-dev/timely-dataflow\", branch = \"ddlog-1\" }" $$
"" $$
dependencies $$
"" $$
Expand Down Expand Up @@ -1992,7 +1994,7 @@ compileRule d rl@Rule{..} last_rhs_idx input_val = {-trace ("compileRule " ++ sh
xform <- mkArrangedOperator conds input_val
return $ "/*" <+> pp rl <+> "*/" $$
"program::Rule::ArrangementRule {" $$
" description: std::borrow::Cow::from(" <+> pp (show $ show rl) <> ")," $$
" description: std::borrow::Cow::from(" <+> pp (show $ render $ rulePPStripped rl) <> ")," $$
" arr: (" <+> relId d (atomRelation fstatom) <> "," <+> pp arid <> ")," $$
" xform:" <+> xform $$
"}"
Expand Down Expand Up @@ -2022,7 +2024,7 @@ compileRule d rl@Rule{..} last_rhs_idx input_val = {-trace ("compileRule " ++ sh
if last_rhs_idx == 0 && input_val
then "/*" <+> pp rl <+> "*/" $$
"program::Rule::CollectionRule {" $$
" description: std::borrow::Cow::from(" <> pp (show $ show rl) <> ")," $$
" description: std::borrow::Cow::from(" <> pp (show $ render $ rulePPStripped rl) <> ")," $$
" rel:" <+> relId d (atomRelation fstatom) <> "," $$
" xform: Some(" <> xform <> ")" $$
"}"
Expand Down Expand Up @@ -2549,7 +2551,7 @@ mkHead d prefix rl =
fmfun = braces' $ prefix $$
"Some" <> parens v
in "XFormCollection::FilterMap{" $$
" description: std::borrow::Cow::from(" <> (pp $ show $ show $ "head of" <+> pp rl) <> ")," $$
" description: std::borrow::Cow::from(" <> (pp $ show $ show $ "head of" <+> rulePPStripped rl) <> ")," $$
nest' ("fmfun: {fn __f(" <> vALUE_VAR <> ": DDValue) -> Option<DDValue>" $$ fmfun $$ "__f},") $$
" next: Box::new(None)" $$
"}"
Expand Down
12 changes: 8 additions & 4 deletions src/Language/DifferentialDatalog/DatalogProgram.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ module Language.DifferentialDatalog.DatalogProgram (
progMirrorInputRelations,
progOutputInternalRelations,
progInjectDebuggingHooks,
ruleExprMapCtxM
)
where

Expand Down Expand Up @@ -79,10 +80,7 @@ progExprMapCtxM d fun = do
Just e -> Just <$> exprFoldCtxM fun (CtxFunc f) e
return f{funcDef = e}))
$ progFunctions d
rules' <- mapM (\r -> do lhs <- mapIdxM (\a i -> atomExprMapCtxM fun (CtxRuleL r i) a) $ ruleLHS r
rhs <- mapIdxM (\x i -> rhsExprMapCtxM fun r i x) $ ruleRHS r
return r{ruleLHS = lhs, ruleRHS = rhs})
$ progRules d
rules' <- mapM (ruleExprMapCtxM fun) $ progRules d
return d{ progFunctions = funcs'
, progRelations = rels'
, progIndexes = idxs'
Expand All @@ -95,6 +93,12 @@ relExprMapCtxM fun rel = do
$ relPrimaryKey rel
return rel{relPrimaryKey = pkey'}

ruleExprMapCtxM :: (Monad m) => (ECtx -> ENode -> m Expr) -> Rule -> m Rule
ruleExprMapCtxM fun r = do
lhs <- mapIdxM (\a i -> atomExprMapCtxM fun (CtxRuleL r i) a) $ ruleLHS r
rhs <- mapIdxM (\x i -> rhsExprMapCtxM fun r i x) $ ruleRHS r
return r{ruleLHS = lhs, ruleRHS = rhs}

atomExprMapCtxM :: (Monad m) => (ECtx -> ENode -> m Expr) -> ECtx -> Atom -> m Atom
atomExprMapCtxM fun ctx a = do
v <- exprFoldCtxM fun ctx $ atomVal a
Expand Down
1 change: 1 addition & 0 deletions src/Language/DifferentialDatalog/Expr.hs-boot
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ exprContainsPHolders :: Expr -> Bool
exprTypeMapM :: (Monad m) => (Type -> m Type) -> Expr -> m Expr
exprIsPure :: DatalogProgram -> ECtx -> Expr -> Bool
exprFreeVars :: DatalogProgram -> ECtx -> Expr -> [Var]
exprStripTypeAnnotationsRec :: Expr -> ECtx -> Expr
20 changes: 18 additions & 2 deletions src/Language/DifferentialDatalog/Rule.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ SOFTWARE.

module Language.DifferentialDatalog.Rule (
rulePPPrefix,
rulePPStripped,
ruleRHSVars,
ruleRHSNewVars,
ruleVars,
Expand All @@ -36,11 +37,12 @@ module Language.DifferentialDatalog.Rule (
ruleGroupByValType,
ruleIsDistinctByConstruction,
ruleHeadIsRecursive,
ruleIsRecursive
ruleIsRecursive,
) where

import qualified Data.Set as S
import Data.List
import Data.Functor.Identity
--import Debug.Trace
import Text.PrettyPrint

Expand All @@ -52,10 +54,24 @@ import Language.DifferentialDatalog.NS
import Language.DifferentialDatalog.Var
import Language.DifferentialDatalog.Relation
import Language.DifferentialDatalog.Type
import Language.DifferentialDatalog.DatalogProgram

-- | Remove all type annotations from the rule. Used to remove the numerous
-- annotations injected by type inference to cleanup the rule before
-- printing it (but also removes all user-defined type annotations, so the
-- resulting rule may no longer type check and should not be used for
-- anything other then pretty-printing).
ruleStripTypeAnnotations :: Rule -> Rule
ruleStripTypeAnnotations rl@Rule{..} =
runIdentity $ ruleExprMapCtxM (\ctx e -> return $ exprStripTypeAnnotationsRec (E e) ctx) rl

-- | Pretty-print the first 'len' literals of a rule.
rulePPPrefix :: Rule -> Int -> Doc
rulePPPrefix rl len = commaSep $ map pp $ take len $ ruleRHS rl
rulePPPrefix rl len = commaSep $ map pp $ take len $ ruleRHS $ ruleStripTypeAnnotations rl

-- | Pretty-print rule without type annotations.
rulePPStripped :: Rule -> Doc
rulePPStripped rl = pp $ ruleStripTypeAnnotations rl

-- | New variables declared in the 'i'th conjunct in the right-hand
-- side of a rule.
Expand Down