[m-rev.] diff: better error message for nonexistent modules

Simon Taylor stayl at cs.mu.OZ.AU
Fri Jul 12 17:31:51 AEST 2002


Estimated hours taken: 0.5
Branches: main

Give a better error message for nonexistent modules specified
in `:- import_module' or `:- include_module' declarations.

compiler/make.m:
compiler/make.dependencies.m:
compiler/make.module_dep_file.m:
	Track which module imported or included the module
	currently being processed when generating dependencies,
	and include the name of the importing module in the error
	message generated when a module can't be found.

tests/invalid/Mmakefile:
tests/invalid/nonexistent_import.{m,err_exp}:
	Test case.

Index: compiler/make.dependencies.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make.dependencies.m,v
retrieving revision 1.6
diff -u -u -r1.6 make.dependencies.m
--- compiler/make.dependencies.m	21 Jun 2002 16:52:46 -0000	1.6
+++ compiler/make.dependencies.m	10 Jul 2002 08:55:58 -0000
@@ -692,12 +692,15 @@
 					Imports ^ foreign_import_module_info)
 			    ])
 		},
+		{ ImportingModule = Info1 ^ importing_module },
+		{ Info2 = Info1 ^ importing_module := yes(ModuleName) },
 		foldl3_maybe_stop_at_error(KeepGoing,
 			find_transitive_module_dependencies_2(KeepGoing,
 				DependenciesType, ModuleLocn),
 				ImportsToCheck, Success,
 				set__insert(Modules0, ModuleName), Modules,
-				Info1, Info)
+				Info2, Info3),
+		{ Info = Info3 ^ importing_module := ImportingModule }
 	    ;
 		{ Success = yes },
 		{ Modules = Modules0 },
Index: compiler/make.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make.m,v
retrieving revision 1.8
diff -u -u -r1.8 make.m
--- compiler/make.m	22 Jun 2002 19:15:54 -0000	1.8
+++ compiler/make.m	10 Jul 2002 08:54:03 -0000
@@ -102,7 +102,11 @@
 
 			% Modules for which we have redirected output
 			% to a `.err' file during this invocation of mmc.
-		error_file_modules :: set(module_name)
+		error_file_modules :: set(module_name),
+
+			% Used for reporting which module imported
+			% a nonexistent module.
+		importing_module :: maybe(module_name)
 	).
 
 :- type make_error
@@ -244,7 +248,7 @@
 		OptionArgs, Variables, map__init,
 		init_cached_direct_imports,
 		init_cached_transitive_dependencies,
-		ShouldRebuildDeps, KeepGoing, set__init) },
+		ShouldRebuildDeps, KeepGoing, set__init, no) },
 
 	globals__io_get_globals(Globals),
 	foldl2_maybe_stop_at_error(KeepGoing,
Index: compiler/make.module_dep_file.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make.module_dep_file.m,v
retrieving revision 1.4
diff -u -u -r1.4 make.module_dep_file.m
--- compiler/make.module_dep_file.m	21 May 2002 19:04:26 -0000	1.4
+++ compiler/make.module_dep_file.m	10 Jul 2002 17:52:46 -0000
@@ -164,6 +164,8 @@
 			io__write_string("' to generate dependencies: "),
 			io__write_string(Message),
 			io__write_string(".\n"),
+			maybe_write_importing_module(ModuleName,
+				Info5 ^ importing_module),
 		    	{ Info6 = Info5 }
 		    )
 		;
@@ -498,6 +500,7 @@
 	    io__write_string("** Error: error reading file `"),
 	    io__write_string(SourceFileName),
 	    io__write_string("' to generate dependencies.\n"),
+	    maybe_write_importing_module(ModuleName, Info0 ^ importing_module),
 
 	    % Display the contents of the `.err' file, then remove it
 	    % so we don't leave `.err' files lying around for nonexistent
@@ -602,5 +605,16 @@
 		remove_file(SubModuleName, module_dep_file_extension,
 			Info1, Info2)
 	    ), SubModuleNames, Info0, Info).
+
+:- pred maybe_write_importing_module(module_name::in, maybe(module_name)::in,
+		io__state::di, io__state::uo) is det.
+
+maybe_write_importing_module(_, no) --> [].
+maybe_write_importing_module(ModuleName, yes(ImportingModuleName)) -->
+	io__write_string("** Module `") ,
+	prog_out__write_sym_name(ModuleName),
+	io__write_string("' is imported or included by module `"),
+	prog_out__write_sym_name(ImportingModuleName),
+	io__write_string("'.\n").
 
 %-----------------------------------------------------------------------------%
Index: tests/invalid/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/invalid/Mmakefile,v
retrieving revision 1.115
diff -u -u -r1.115 Mmakefile
--- tests/invalid/Mmakefile	9 Jul 2002 01:31:02 -0000	1.115
+++ tests/invalid/Mmakefile	12 Jul 2002 07:20:04 -0000
@@ -82,6 +82,7 @@
 	multisoln_func.m \
 	nested_impl_in_int.m \
 	no_exports.m \
+	nonexistent_import.m \
 	not_a_switch.m \
 	nullary_ho_func_error.m \
 	occurs.m \
@@ -188,6 +189,7 @@
 MCFLAGS-multisoln_func	=	--infer-types
 MCFLAGS-mode_inf	=	--infer-all
 MCFLAGS-no_exports = 		--halt-at-warn
+MCFLAGS-nonexistent_import =	--no-verbose-make --make nonexistent_import
 MCFLAGS-overloading = 		--no-intermodule-optimization
 MCFLAGS-sub_c = 	--verbose-error-messages --no-intermodule-optimization
 MCFLAGS-record_syntax_errors =	--verbose-error-messages
Index: tests/invalid/nonexistent_import.err_exp
===================================================================
RCS file: tests/invalid/nonexistent_import.err_exp
diff -N tests/invalid/nonexistent_import.err_exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/invalid/nonexistent_import.err_exp	12 Jul 2002 07:20:24 -0000
@@ -0,0 +1,3 @@
+** Error: error reading file `nonexistent.m' to generate dependencies.
+** Module `nonexistent' is imported or included by module `nonexistent_import'.
+mercury_compile: can't find source for module `nonexistent'.
Index: tests/invalid/nonexistent_import.m
===================================================================
RCS file: tests/invalid/nonexistent_import.m
diff -N tests/invalid/nonexistent_import.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/invalid/nonexistent_import.m	12 Jul 2002 07:20:11 -0000
@@ -0,0 +1,7 @@
+:- module nonexistent_import.
+
+:- interface.
+
+:- type foo == int.
+
+:- import_module nonexistent.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list