diff --git a/CHANGELOG.md b/CHANGELOG.md index f85e639f9..6b9e5b54c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/Language/DifferentialDatalog/Compile.hs b/src/Language/DifferentialDatalog/Compile.hs index 454fd7135..6de4c958a 100644 --- a/src/Language/DifferentialDatalog/Compile.hs +++ b/src/Language/DifferentialDatalog/Compile.hs @@ -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 @@ -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 diff --git a/src/Language/DifferentialDatalog/Module.hs b/src/Language/DifferentialDatalog/Module.hs index ee5a3ebfc..1f9ea779d 100644 --- a/src/Language/DifferentialDatalog/Module.hs +++ b/src/Language/DifferentialDatalog/Module.hs @@ -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 } diff --git a/src/Language/DifferentialDatalog/Parse.hs b/src/Language/DifferentialDatalog/Parse.hs index fd43ba13f..89cce4d19 100644 --- a/src/Language/DifferentialDatalog/Parse.hs +++ b/src/Language/DifferentialDatalog/Parse.hs @@ -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 diff --git a/test/datalog_tests/modules.dl b/test/datalog_tests/modules.dl index 31fd1c06a..b6ff2ab34 100644 --- a/test/datalog_tests/modules.dl +++ b/test/datalog_tests/modules.dl @@ -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) diff --git a/test/datalog_tests/stream.dat b/test/datalog_tests/streams.dat similarity index 100% rename from test/datalog_tests/stream.dat rename to test/datalog_tests/streams.dat diff --git a/test/datalog_tests/stream.dl b/test/datalog_tests/streams.dl similarity index 100% rename from test/datalog_tests/stream.dl rename to test/datalog_tests/streams.dl diff --git a/test/datalog_tests/stream.dump.expected b/test/datalog_tests/streams.dump.expected similarity index 100% rename from test/datalog_tests/stream.dump.expected rename to test/datalog_tests/streams.dump.expected diff --git a/test/datalog_tests/test-stream.sh b/test/datalog_tests/test-stream.sh index f0a2e214c..ae9bbbabc 100755 --- a/test/datalog_tests/test-stream.sh +++ b/test/datalog_tests/test-stream.sh @@ -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. @@ -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() { @@ -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 } @@ -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 }