[m-rev.] for review: Fix writing fact table file names in .module_dep files.

Peter Wang novalazy at gmail.com
Mon Dec 5 15:09:36 AEDT 2022


Commit 5f50259d16c12286261d070f04d66f2ab19ced92 inadvertently wrote out
the list of fact table file names in a .module_dep file without quoting,
so the .module_dep parser would fail to read it back.

compiler/make.module_dep_file.m:
    Write fact table file names in .module_dep files as quoted strings.

tests/mmc_make/Mmakefile:
tests/mmc_make/factt.m:
tests/mmc_make/factt_examples:
    Add a test case.

diff --git a/compiler/make.module_dep_file.m b/compiler/make.module_dep_file.m
index eca901660..f1c554e9d 100644
--- a/compiler/make.module_dep_file.m
+++ b/compiler/make.module_dep_file.m
@@ -389,9 +389,10 @@ do_write_module_dep_file_to_stream(Stream, Globals,
     MaybeTopModule = Baggage ^ mb_maybe_top_module,
     NestedSubModules = get_nested_children_list_of_top_module(MaybeTopModule),
     get_fact_tables(ParseTreeModuleSrc, FactTableFilesSet),
-    set.to_sorted_list(FactTableFilesSet, FactTableFiles),
+    FactTableFilesStrs = list.map(term_io.quoted_string,
+        set.to_sorted_list(FactTableFilesSet)),
     globals.get_backend_foreign_languages(Globals, BackendLangsList),
-    BackendLangs = set.list_to_set(BackendLangsList), 
+    BackendLangs = set.list_to_set(BackendLangsList),
     get_foreign_code_langs(ParseTreeModuleSrc, CodeLangs),
     get_foreign_export_langs(ParseTreeModuleSrc, ExportLangs),
     set.intersect(BackendLangs, CodeLangs, BackendCodeLangs),
@@ -434,7 +435,7 @@ do_write_module_dep_file_to_stream(Stream, Globals,
         s(bracketed_sym_names_to_comma_list_string(ImpDeps)),
         s(bracketed_sym_names_to_comma_list_string(Children)),
         s(bracketed_sym_names_to_comma_list_string(NestedSubModules)),
-        s(string.join_list(", ", FactTableFiles)),
+        s(string.join_list(", ", FactTableFilesStrs)),
         s(string.join_list(", ", CodeLangStrs)),
         s(string.join_list(", ", FIMSpecStrs)),
         s(ContainsForeignExportStr),
diff --git a/tests/mmc_make/Mmakefile b/tests/mmc_make/Mmakefile
index 2d18369e0..ce272b4a6 100644
--- a/tests/mmc_make/Mmakefile
+++ b/tests/mmc_make/Mmakefile
@@ -10,7 +10,7 @@ MAYBE_J1 =
 
 MMAKE_USE_MMC_MAKE=yes
 
-PROGS =	\
+PROGS0 =	\
 	bug489 \
 	complex_test \
 	hello \
@@ -19,6 +19,15 @@ PROGS =	\
 	linkage_test \
 	rebuild
 
+ifeq "$(filter csharp% java%,$(GRADE))" ""
+	C_ONLY_PROGS = \
+		factt
+else
+	C_ONLY_PROGS =
+endif
+
+PROGS = $(PROGS0) $(C_ONLY_PROGS)
+
 # These tests only work if the workspace was compiled with `--use-subdirs'.
 ifneq ($(origin WORKSPACE),undefined)
     ifeq ($(shell [ -d $(WORKSPACE)/library/Mercury ] || echo cannot_run),cannot_run)
@@ -58,6 +67,13 @@ rebuild.runtest:
 # The compiler used to fail when invoked as `mmc --make build_object.o'.
 build_object.runtest: build_object.o
 
+# Check that no errors occur while reading back the .module_dep file on the
+# second run.
+factt.runtest:
+	$(MCM) --make factt
+	$(MCM) --make factt >factt.err2 2>&1
+	! grep -i 'Error' factt.err2
+
 .PHONY: install_libs
 install_libs: start_runtests_local
 	$(MMAKE) TESTS_FLAGS
@@ -82,7 +98,7 @@ TESTS_FLAGS: ../TESTS_FLAGS
 realclean_local: realclean_mmc_make
 
 realclean_mmc_make: TESTS_FLAGS
-	rm -rf install include_file2.err rebuild.err2
+	rm -rf install include_file2.err rebuild.err2 factt.err2
 	# ./TESTS_FLAGS is expected by the following line.
 	cd lib; $(MCM) complex_numbers.realclean linkage_test2.realclean
 	rm -f TESTS_FLAGS
diff --git a/tests/mmc_make/factt.m b/tests/mmc_make/factt.m
new file mode 100644
index 000000000..e1b08770f
--- /dev/null
+++ b/tests/mmc_make/factt.m
@@ -0,0 +1,39 @@
+%---------------------------------------------------------------------------%
+% vim: ts=4 sw=4 et ft=mercury
+%---------------------------------------------------------------------------%
+
+:- module factt.
+:- interface.
+
+:- import_module io.
+:- pred main(io::di, io::uo) is det.
+
+%---------------------------------------------------------------------------%
+
+:- implementation.
+
+:- import_module int.
+:- import_module list.
+:- import_module string.
+
+:- pred example(int::in, int::out, int::out) is semidet.
+:- pragma fact_table(example/3, "factt_examples").
+
+%---------------------------------------------------------------------------%
+
+main(!IO) :-
+    show_examples(1, !IO).
+
+:- pred show_examples(int::in, io::di, io::uo) is det.
+
+show_examples(Cur, !IO) :-
+    ( if Cur > 50 then
+        true
+    else
+        ( if example(Cur, A, B) then
+            io.format("%2d %2d %2d\n", [i(Cur), i(A), i(B)], !IO)
+        else
+            io.format("%2d  -  -\n", [i(Cur)], !IO)
+        ),
+        show_examples(Cur + 1, !IO)
+    ).
diff --git a/tests/mmc_make/factt_examples b/tests/mmc_make/factt_examples
new file mode 100644
index 000000000..55a644af4
--- /dev/null
+++ b/tests/mmc_make/factt_examples
@@ -0,0 +1,4 @@
+example(1,0,1).
+%to
+example(50,1,50).
+
-- 
2.38.0



More information about the reviews mailing list