Skip to content

Commit cfba7f6

Browse files
committed
DatalogProgram.hs: Broken visitor
The expression visitor implementation, which is supposed to visit all expressions in the program, ignored primary key expressions.
1 parent cf86cfa commit cfba7f6

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/Language/DifferentialDatalog/DatalogProgram.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ import Language.DifferentialDatalog.Type
6565
-- | Map function 'fun' over all expressions in a program
6666
progExprMapCtxM :: (Monad m) => DatalogProgram -> (ECtx -> ENode -> m Expr) -> m DatalogProgram
6767
progExprMapCtxM d fun = do
68+
rels' <- M.fromList <$>
69+
(mapM (\(rname, rel) -> (rname,) <$> relExprMapCtxM fun rel) $ M.toList $ progRelations d)
6870
funcs' <- mapM (\f -> do e <- case funcDef f of
6971
Nothing -> return Nothing
7072
Just e -> Just <$> exprFoldCtxM fun (CtxFunc f) e
@@ -75,8 +77,16 @@ progExprMapCtxM d fun = do
7577
return r{ruleLHS = lhs, ruleRHS = rhs})
7678
$ progRules d
7779
return d{ progFunctions = funcs'
80+
, progRelations = rels'
7881
, progRules = rules'}
7982

83+
relExprMapCtxM :: (Monad m) => (ECtx -> ENode -> m Expr) -> Relation -> m Relation
84+
relExprMapCtxM fun rel = do
85+
pkey' <- mapM (\key -> do e' <- exprFoldCtxM fun (CtxKey rel) $ keyExpr key
86+
return key{keyExpr = e'})
87+
$ relPrimaryKey rel
88+
return rel{relPrimaryKey = pkey'}
89+
8090
atomExprMapCtxM :: (Monad m) => (ECtx -> ENode -> m Expr) -> ECtx -> Atom -> m Atom
8191
atomExprMapCtxM fun ctx a = do
8292
v <- exprFoldCtxM fun ctx $ atomVal a

test/datalog_tests/constr.fail.ast.expected

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ expecting function name
2020

2121
error: ./test/datalog_tests/constr.fail.dl:4:15-7:1: Field x is declared with different types
2222

23-
error: ./test/datalog_tests/constr.fail.dl:4:1-6:1: The following type variables are not used in type definition: D
23+
error: ./test/datalog_tests/constr.fail.dl:4:1-7:1: The following type variables are not used in type definition: D
24+
25+
./test/datalog_tests/constr.fail.dl:6:54-7:1: Unknown module vm. Did you forget to import it?

test/datalog_tests/constr.fail.dl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,10 @@ typedef Alt = C0{x: bit<16>}
3333
// type argument 'D not used in type definition
3434
typedef Parameterized<'A,'B,'C,'D> = Option1{x: 'A}
3535
| Option2{y: 'B, z: 'C}
36+
37+
//---
38+
39+
typedef VIP = string
40+
typedef UUID = string
41+
42+
input relation VM_Host[(VIP, UUID)] primary key (vm) vm.VIP

0 commit comments

Comments
 (0)