Skip to content

Commit

Permalink
Bug in simplifyDifferentiation.
Browse files Browse the repository at this point in the history
When generating auxiliary relations for differentiation and delay
operators, we incorrectly added the prefix to the fully qualified
relation name instead of the local component of the name.  As a result,
the compiler crashed when such relations were declared anywhere other
than the main module.
  • Loading branch information
ryzhyk committed Feb 24, 2021
1 parent 789fb5b commit bfd4574
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

- [C API tutorial](doc/c_tutorial/c_tutorial.rst), kindly contributed by @smadaminov.

### Bug fix

- Compiler crashed when differentiation or delay operators were applied to
relations declared outside of the main module of the program.

## [0.37.0] - Feb 15, 2021

### Language improvements
Expand Down
11 changes: 9 additions & 2 deletions src/Language/DifferentialDatalog/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,11 @@ simplifyDelayedRels d =
delayed_rels d'
where
mk_delayed_rel_name :: (String, Delay) -> String
mk_delayed_rel_name (rel, del) = "__" ++ show (delayDelay del) ++ "_" ++ rel
mk_delayed_rel_name (rel, del) = scoped rel_scope $ "__" ++ show (delayDelay del) ++ "_" ++ rel_name
where
rel_scope = nameScope rel
rel_name = nameLocalStr rel

-- Find all delayed rels in the program, replacing each occurrence
-- of 'R-n' with '__n_R'.
(delayed_rels, d') = runState
Expand Down Expand Up @@ -682,7 +686,10 @@ simplifyDifferentiation d =
diff_rels d'
where
mk_diff_rel_name :: String -> String
mk_diff_rel_name rname = "__diff_" ++ rname
mk_diff_rel_name rname = scoped rel_scope $ "__diff_" ++ rel_name
where
rel_scope = nameScope rname
rel_name = nameLocalStr rname
-- Find all differentiated rels in the program, replacing each occurrence
-- of 'R'' with '__diff_R'.
(diff_rels, d') = runState
Expand Down
1 change: 0 additions & 1 deletion src/Language/DifferentialDatalog/Module.hs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ stdImports = map stdImport stdLibs
parseDatalogProgram :: [FilePath] -> Bool -> String -> FilePath -> ExceptT String IO ([DatalogModule], DatalogProgram, M.Map ModuleName (Doc, Doc, Doc))
parseDatalogProgram roots import_std fdata fname = do
roots' <- lift $ nub <$> mapM canonicalizePath roots
-- TODO: parseDatalogProgram should return ExceptT.
prog <- parseDatalogString fdata fname
let prog' = if import_std
then prog { progImports = stdImports ++ progImports prog }
Expand Down
2 changes: 1 addition & 1 deletion src/Language/DifferentialDatalog/Parse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import Language.DifferentialDatalog.Ops
import Language.DifferentialDatalog.Error
import {-# SOURCE #-} Language.DifferentialDatalog.Expr

-- parse a string containing a datalog program and produce the intermediate representation
-- parse a string containing a DDlog program and produce the intermediate representation.
parseDatalogString :: String -> String -> ExceptT String IO DatalogProgram
parseDatalogString program file = do
case parse datalogGrammar file program of
Expand Down
2 changes: 2 additions & 0 deletions test/datalog_tests/modules.dl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import foolib::lib
import foolib::ns1::m1 as m1
import foolib::ns1::m2 as m2
import redist
// Make sure we can compile streaming code that lives in a module.
import streams

input relation Rmain(f1: Tlib, f2: m1::T1)
output relation Rout(f1: bool, f2: bigint)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions test/datalog_tests/test-stream.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

./run-test.sh stream release
./run-test.sh streams release

run_test() {
echo Running mem leak test for $1 iterations.
Expand All @@ -13,7 +13,7 @@ run_test() {
insert Chunk(\"{\\\"fild\\\": $i}\"),
commit dump_changes;"
done) |
/usr/bin/time -o stream_mem -f "%M" ./stream_ddlog/target/release/stream_cli -w 4 --no-store > stream_mem.dump
/usr/bin/time -o stream_mem -f "%M" ./streams_ddlog/target/release/streams_cli -w 4 --no-store > stream_mem.dump
}

run_memleak_test() {
Expand Down Expand Up @@ -50,7 +50,7 @@ run_stream_query_test() {
done
echo "commit dump_changes;"
done) > stream_bench.dat
/usr/bin/time ./stream_ddlog/target/release/stream_cli -w $3 --no-store < stream_bench.dat > stream_stream_queries.dump
/usr/bin/time ./streams_ddlog/target/release/streams_cli -w $3 --no-store < stream_bench.dat > stream_stream_queries.dump

}

Expand Down Expand Up @@ -82,7 +82,7 @@ run_rel_query_test() {
echo "commit dump_changes;"

done) > stream_bench.dat
/usr/bin/time ./stream_ddlog/target/release/stream_cli -w $3 --no-store < stream_bench.dat > stream_rel_queries.dump
/usr/bin/time ./streams_ddlog/target/release/streams_cli -w $3 --no-store < stream_bench.dat > stream_rel_queries.dump

}

Expand Down

0 comments on commit bfd4574

Please sign in to comment.