[m-rev.] no commit: Improve an error message for missing source files.

Paul Bone paul at bone.id.au
Wed Oct 21 15:09:53 AEDT 2015


This is an expriment, I'm not proposing to commit it.

---

Improve an error message for missing source files.

When a source file is missing Mercury reports which other source file included
it, but not the whole chain of dependencies.  This is an experiment to report
the whole chain to see if it's more useful.

It doesn't appear to be useful.  Since it often includes the builtin module
and can get quite long.  The example here is a small one:

** Module `string' is imported or included by the chain of modules: `builtin' -> `private_builtin' -> `int' -> `table_builtin' -> `io' -> `char' -> `require'.

compiler/make.module_dep_file.m:
    As above.

compiler/make.m:
compiler/make.dependencies.m:
    Track the "stack" of dependencies as we calculate module dependencies.
---
 compiler/make.dependencies.m    |  6 +++---
 compiler/make.m                 |  8 ++++----
 compiler/make.module_dep_file.m | 35 +++++++++++++++++++++++++----------
 3 files changed, 32 insertions(+), 17 deletions(-)

diff --git a/compiler/make.dependencies.m b/compiler/make.dependencies.m
index 34f2d1a..f533130 100644
--- a/compiler/make.dependencies.m
+++ b/compiler/make.dependencies.m
@@ -1238,15 +1238,15 @@ find_transitive_module_dependencies_2(KeepGoing, DependenciesType, ModuleLocn,
                 ),
                 module_names_to_index_set(set.to_sorted_list(ImportsToCheck),
                     ImportsToCheckSet, !Info),
-                ImportingModule = !.Info ^ importing_module,
-                !Info ^ importing_module := yes(ModuleName),
+                ImportingModules = !.Info ^ importing_modules,
+                !Info ^ importing_modules := [ModuleName | ImportingModules],
                 Modules1 = insert(Modules0, ModuleIndex),
                 deps_set_foldl3_maybe_stop_at_error(KeepGoing,
                     find_transitive_module_dependencies_2(KeepGoing,
                         DependenciesType, ModuleLocn),
                     Globals, ImportsToCheckSet, Success, Modules1, Modules,
                     !Info, !IO),
-                !Info ^ importing_module := ImportingModule
+                !Info ^ importing_modules := ImportingModules
             else
                 Success = yes,
                 Modules = Modules0
diff --git a/compiler/make.m b/compiler/make.m
index ac912c9..f3eda93 100644
--- a/compiler/make.m
+++ b/compiler/make.m
@@ -156,9 +156,9 @@
                 % to a `.err' file during this invocation of mmc.
                 error_file_modules      :: set(module_name),
 
-                % Used for reporting which module imported a nonexistent
-                % module.
-                importing_module        :: maybe(module_name),
+                % Used for reporting the chain of modules which imported a
+                % nonexistent module.
+                importing_modules       :: list(module_name),
 
                 % Targets specified on the command line.
                 command_line_targets    :: set(pair(module_name, target_type)),
@@ -372,7 +372,7 @@ make_process_args(Globals, DetectedGradeFlags, Variables, OptionArgs,
             ShouldRebuildModuleDeps,
             KeepGoing,
             set.init,
-            no,
+            [],
             set.list_to_set(ClassifiedTargets),
             AnalysisRepeat,
             no
diff --git a/compiler/make.module_dep_file.m b/compiler/make.module_dep_file.m
index 4ba760a..3963b0e 100644
--- a/compiler/make.module_dep_file.m
+++ b/compiler/make.module_dep_file.m
@@ -235,8 +235,8 @@ do_get_module_dependencies(Globals, RebuildModuleDeps, ModuleName,
                 io.write_string("' to generate dependencies: ", !IO),
                 io.write_string(Message, !IO),
                 io.write_string(".\n", !IO),
-                maybe_write_importing_module(ModuleName,
-                    !.Info ^ importing_module, !IO)
+                maybe_write_importing_modules(ModuleName,
+                    !.Info ^ importing_modules, !IO)
             )
         else
             true
@@ -836,8 +836,8 @@ make_module_dependencies(Globals, ModuleName, !Info, !IO) :-
             io.write_string("** Error reading file `", !IO),
             io.write_string(SourceFileName, !IO),
             io.write_string("' to generate dependencies.\n", !IO),
-            maybe_write_importing_module(ModuleName, !.Info ^ importing_module,
-                !IO),
+            maybe_write_importing_modules(ModuleName,
+                !.Info ^ importing_modules, !IO),
 
             % Display the contents of the `.err' file, then remove it
             % so we don't leave `.err' files lying around for nonexistent
@@ -951,16 +951,31 @@ cleanup_module_dep_files(Globals, SubModuleNames, !Info, !IO) :-
                 make_module_dep_file_extension, !Info, !IO)
         ), SubModuleNames, !Info, !IO).
 
-:- pred maybe_write_importing_module(module_name::in, maybe(module_name)::in,
+:- pred maybe_write_importing_modules(module_name::in, list(module_name)::in,
     io::di, io::uo) is det.
 
-maybe_write_importing_module(_, no, !IO).
-maybe_write_importing_module(ModuleName, yes(ImportingModuleName), !IO) :-
+maybe_write_importing_modules(_, [], !IO).
+maybe_write_importing_modules(ModuleName,
+        [ImportingModuleName | ImportingModuleNames], !IO) :-
     io.write_string("** Module `", !IO),
     write_sym_name(ModuleName, !IO),
-    io.write_string("' is imported or included by module `", !IO),
-    write_sym_name(ImportingModuleName, !IO),
-    io.write_string("'.\n", !IO).
+    io.write_string("' is imported or included by the chain of modules: ", !IO),
+    write_importing_modules_chain(
+        [ImportingModuleName | ImportingModuleNames], !IO),
+    io.write_string(".\n", !IO).
+
+:- pred write_importing_modules_chain(list(module_name)::in(non_empty_list),
+    io::di, io::uo) is det.
+
+write_importing_modules_chain([Module | Modules], !IO) :-
+    (
+        Modules = [],
+        format("`%s'", [s(sym_name_to_escaped_string(Module))], !IO)
+    ;
+        Modules = [_ | _],
+        write_importing_modules_chain(Modules, !IO),
+        format(" -> `%s'", [s(sym_name_to_escaped_string(Module))], !IO)
+    ).
 
 %-----------------------------------------------------------------------------%
 :- end_module make.module_dep_file.
-- 
2.6.1




More information about the reviews mailing list