diff: warn about modules with no exports

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Oct 28 17:14:09 AEDT 1998


[DJ already did an over-the-shoulder review of this one.]

Estimated hours taken: 1

compiler/modules.m:
compiler/mercury_compile.m:
	Warn about modules with no exports when compiling,
	not just when making interfaces.  Previous it would
	only issue this warning when doing `mmc --make-int',
	not when doing `mmc --compile-to-c'.

tests/invalid/Mmakefile:
tests/invalid/no_exports.err_exp:
	Enable the already-existing test case for this.

Index: compiler/mercury_compile.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.108
diff -u -r1.108 mercury_compile.m
--- mercury_compile.m	1998/10/16 06:17:35	1.108
+++ mercury_compile.m	1998/10/28 05:37:03
@@ -317,6 +317,7 @@
 :- mode compile(in, in, di, uo) is det.
 
 compile(SourceFileName, ModuleName - Items) -->
+	check_for_no_exports(Items, ModuleName),
 	grab_imported_modules(SourceFileName, ModuleName, Items,
 		Module, Error2),
 	( { Error2 \= fatal } ->
Index: compiler/modules.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modules.m,v
retrieving revision 1.87
diff -u -r1.87 modules.m
--- modules.m	1998/09/29 05:10:27	1.87
+++ modules.m	1998/10/28 05:35:44
@@ -467,6 +467,14 @@
 :- pred pragma_allowed_in_interface(pragma_type, bool).
 :- mode pragma_allowed_in_interface(in, out) is det.
 
+	% Given a module name and a list of the items in that module,
+	% this procedure checks if the module doesn't export anything,
+	% and if so, and --warn-nothing-exported is set, it reports
+	% a warning.
+
+:- pred check_for_no_exports(item_list, module_name, io__state, io__state).
+:- mode check_for_no_exports(in, in, di, uo) is det.
+
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
@@ -713,7 +721,7 @@
 							InterfaceItems3) },
 			check_for_clauses_in_interface(InterfaceItems3,
 							InterfaceItems),
-			check_for_no_exports(InterfaceItems, ModuleName),
+			check_int_for_no_exports(InterfaceItems, ModuleName),
 			write_interface_file(ModuleName, ".int",
 							InterfaceItems),
 			{ get_short_interface(InterfaceItems,
@@ -848,12 +856,25 @@
 pragma_allowed_in_interface(does_not_terminate(_, _), yes).
 pragma_allowed_in_interface(check_termination(_, _), yes).
 
-:- pred check_for_no_exports(item_list, module_name, io__state, io__state).
-:- mode check_for_no_exports(in, in, di, uo) is det.
+check_for_no_exports(Items, ModuleName) -->
+	globals__io_lookup_bool_option(warn_nothing_exported, ExportWarning),
+	( { ExportWarning = no } ->
+		[]
+	;
+		{ get_interface(Items, no, InterfaceItems) },
+		check_int_for_no_exports(InterfaceItems, ModuleName)
+	).
+
+	% Given a module name and a list of the items in that module's
+	% interface, this procedure checks if the module doesn't export
+	% anything, and if so, and --warn-nothing-exported is set, it reports
+	% a warning.
+:- pred check_int_for_no_exports(item_list, module_name, io__state, io__state).
+:- mode check_int_for_no_exports(in, in, di, uo) is det.
 
-check_for_no_exports([], ModuleName) -->
+check_int_for_no_exports([], ModuleName) -->
 	warn_no_exports(ModuleName).
-check_for_no_exports([Item - _Context | Items], ModuleName) -->
+check_int_for_no_exports([Item - _Context | Items], ModuleName) -->
 	(
 		{ Item = nothing
 		; Item = module_defn(_, ModuleDefn),
@@ -861,7 +882,7 @@
 		}
 	->
 		% nothing useful - keep searching
-		check_for_no_exports(Items, ModuleName)
+		check_int_for_no_exports(Items, ModuleName)
 	;
 		% we found something useful - don't issue the warning
 		[]
@@ -3537,6 +3558,7 @@
 
 :- pred get_interface(item_list, bool, item_list).
 :- mode get_interface(in, in, out) is det.
+
 get_interface(Items0, IncludeImported, Items) :-
 	get_interface_2(Items0, no, IncludeImported, [], RevItems),
 	list__reverse(RevItems, Items).
Index: tests/invalid/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/invalid/Mmakefile,v
retrieving revision 1.29
diff -u -r1.29 Mmakefile
--- Mmakefile	1998/10/07 04:07:54	1.29
+++ Mmakefile	1998/10/28 06:01:48
@@ -31,6 +31,7 @@
 	mostly_uniq2.m \
 	multisoln_func.m \
 	nested_impl_in_int.m \
+	no_exports.m \
 	nullary_ho_func_error.m \
 	occurs.m \
 	pragma_c_code_and_clauses1.m \
@@ -62,7 +63,6 @@
 #	parent.undeclared_child.m (just not yet implemented)
 #	sub_b.m and sub_c.m (bug with dependencies & nested modules)
 #	freefree.m 	(need bromage's aliasing stuff)
-#	no_exports.m	(this is really a WISHLIST item)
 #
 # we do a very bad job on the following tests:
 #	typeclass_test_4.m (awful error message)
@@ -71,6 +71,7 @@
 MCFLAGS-any_mode	=	--infer-types
 MCFLAGS-duplicate_modes	=	--verbose-error-messages
 MCFLAGS-missing_interface_import = --make-interface
+MCFLAGS-no_exports = 		--halt-at-warn
 
 # The bug is caught when generating dependencies, so it is
 # easiest just to do that step.
Index: tests/invalid/no_exports.err_exp
===================================================================
RCS file: /home/mercury1/repository/tests/invalid/no_exports.err_exp,v
retrieving revision 1.1
diff -u -r1.1 no_exports.err_exp
--- no_exports.err_exp	1997/04/27 05:28:53	1.1
+++ no_exports.err_exp	1998/10/28 06:03:42
@@ -1 +1,2 @@
-XXX
+no_exports.m:  1: Warning: interface for module `no_exports' does not export anything.
+For more information, try recompiling with `-E'.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.



More information about the developers mailing list