[m-dev.] for review: fix intermodule optimization bugs

Simon Taylor stayl at cs.mu.OZ.AU
Fri Nov 12 16:19:25 AEDT 1999



Estimated hours taken: 2

Fix two bugs in intermodule optimization reported by Warwick Harvey.

compiler/intermod.m:
	Don't read `.opt' files for nested modules. The compiler
	currently doesn't read in the `.int0' files for parent modules
	of modules for which `.opt' files are read, resulting in
	undefined symbol errors. 

	Export predicate `update_error_status' for use by trans_opt.m.

compiler/trans_opt.m:
	Use intermod__update_error_status to check whether an
	error should be reported if a `.trans_opt' file is not found.
	This is difficult to write a test case for because it would
	be spread across multiple directories.

compiler/options.m:
doc/user_guide.texi:
	Add option --warn-missing-trans-opt-files.

tests/valid/Mmakefile:
tests/valid/intermod_nested_module.m:
tests/valid/intermod_nested_module2.m:
	Test case.



Index: compiler/intermod.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/intermod.m,v
retrieving revision 1.74
diff -u -u -r1.74 intermod.m
--- intermod.m	1999/11/11 23:11:54	1.74
+++ intermod.m	1999/11/12 04:22:56
@@ -37,7 +37,7 @@
 :- interface.
 
 :- import_module io, bool.
-:- import_module hlds_module, modules.
+:- import_module hlds_module, modules, prog_io, prog_data.
 
 :- pred intermod__write_optfile(module_info, module_info,
 				io__state, io__state).
@@ -55,6 +55,28 @@
 		io__state, io__state).
 :- mode intermod__adjust_pred_import_status(in, out, di, uo) is det.
 
+:- type opt_file_type
+	--->	opt
+	;	trans_opt
+	.
+
+	% intermod__update_error_status(OptFileType, FileName, Error, Messages,
+	% 	Status0, Status)
+	%
+	% Work out whether any fatal errors have occurred while reading
+	% `.opt' files, updating Status0 if there were fatal errors.
+	%
+	% A missing `.opt' file is only a fatal error if
+	% `--warn-missing-opt-files --halt-at-warn' was passed
+	% the compiler.
+	%
+	% Syntax errors in `.opt' files are always fatal.
+	%
+	% This is also used by trans_opt.m for reading `.trans_opt' files.
+:- pred intermod__update_error_status(opt_file_type, string, module_error,
+		message_list, bool, bool, io__state, io__state).
+:- mode intermod__update_error_status(in, in, in, in, in, out, di, uo) is det.
+
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
@@ -66,7 +88,7 @@
 :- import_module code_util, globals, goal_util, term, varset.
 :- import_module hlds_data, hlds_goal, hlds_pred, hlds_out, inlining, llds.
 :- import_module mercury_to_mercury, mode_util, modules.
-:- import_module options, passes_aux, prog_data, prog_io, prog_out, prog_util.
+:- import_module options, passes_aux, prog_out, prog_util.
 :- import_module special_pred, typecheck, type_util, instmap, (inst).
 
 %-----------------------------------------------------------------------------%
@@ -1731,27 +1753,37 @@
 read_optimization_interfaces([], Items, Items, Error, Error) --> [].
 read_optimization_interfaces([Import | Imports],
 		Items0, Items, Error0, Error) -->
-	globals__io_lookup_bool_option(very_verbose, VeryVerbose),
-	maybe_write_string(VeryVerbose,
-			"% Reading optimization interface for module"),
-	maybe_write_string(VeryVerbose, " `"),
-	{ prog_out__sym_name_to_string(Import, ImportString) },
-	maybe_write_string(VeryVerbose, ImportString),
-	maybe_write_string(VeryVerbose, "'... "),
-	maybe_flush_output(VeryVerbose),
-	maybe_write_string(VeryVerbose, "% done.\n"),
-
-	module_name_to_file_name(Import, ".opt", no, FileName),
-	prog_io__read_opt_file(FileName, Import, yes,
-			ModuleError, Messages, Items1),
-	update_error_status(FileName, ModuleError, Messages, Error0, Error1),
-	{ list__append(Items0, Items1, Items2) },
+	( { Import = qualified(_, _) } ->
+		% Don't read in optimization interfaces for
+		% nested modules, because we also need to read in
+		% the `.int0' file for the parent modules.
+		% Reading them in may cause problems because the
+		% `.int0' files duplicate information in the `.int'
+		% files.
+		{ Error1 = Error0 },
+		{ Items2 = Items0 }
+	;
+		globals__io_lookup_bool_option(very_verbose, VeryVerbose),
+		maybe_write_string(VeryVerbose,
+				"% Reading optimization interface for module"),
+		maybe_write_string(VeryVerbose, " `"),
+		{ prog_out__sym_name_to_string(Import, ImportString) },
+		maybe_write_string(VeryVerbose, ImportString),
+		maybe_write_string(VeryVerbose, "'... "),
+		maybe_flush_output(VeryVerbose),
+		maybe_write_string(VeryVerbose, "% done.\n"),
+
+		module_name_to_file_name(Import, ".opt", no, FileName),
+		prog_io__read_opt_file(FileName, Import, yes,
+				ModuleError, Messages, Items1),
+		update_error_status(opt, FileName, ModuleError, Messages,
+				Error0, Error1),
+		{ list__append(Items0, Items1, Items2) }
+	),
 	read_optimization_interfaces(Imports, Items2, Items, Error1, Error).
-
-:- pred update_error_status(string::in, module_error::in, message_list::in, 
-		bool::in, bool::out, io__state::di, io__state::uo) is det.
 
-update_error_status(FileName, ModuleError, Messages, Error0, Error1) -->
+update_error_status(FileType, FileName, ModuleError, Messages,
+		Error0, Error1) -->
 	(
 		{ ModuleError = no },
 		{ Error1 = Error0 }
@@ -1761,7 +1793,14 @@
 		{ Error1 = yes }
 	;
 		{ ModuleError = fatal },
-		globals__io_lookup_bool_option(warn_missing_opt_files, DoWarn),
+		{
+			FileType = opt,
+			WarningOption = warn_missing_opt_files
+		;
+			FileType = trans_opt,
+			WarningOption = warn_missing_trans_opt_files
+		},
+		globals__io_lookup_bool_option(WarningOption, DoWarn),
 		( { DoWarn = yes } ->
 			io__write_string("Warning: cannot open `"),
 			io__write_string(FileName),
Index: compiler/options.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/options.m,v
retrieving revision 1.271
diff -u -u -r1.271 options.m
--- options.m	1999/11/06 05:03:50	1.271
+++ options.m	1999/11/12 05:04:41
@@ -55,6 +55,7 @@
 		;	warn_unused_args
 		;	warn_interface_imports
 		;	warn_missing_opt_files
+		;	warn_missing_trans_opt_files
 		;	warn_missing_trans_opt_deps
 		;	warn_non_stratification
 		;	warn_simple_code
@@ -411,6 +412,7 @@
 	warn_interface_imports	-	bool(yes),
 	warn_non_stratification -	bool(no),
 	warn_missing_opt_files  -	bool(yes),
+	warn_missing_trans_opt_files -	bool(no),
 	warn_missing_trans_opt_deps  -	bool(yes),
 	warn_simple_code	-	bool(yes),
 	warn_duplicate_calls	-	bool(no),
@@ -762,6 +764,7 @@
 long_option("warn-interface-imports",	warn_interface_imports).
 long_option("warn-non-stratification",	warn_non_stratification).
 long_option("warn-missing-opt-files",	warn_missing_opt_files).
+long_option("warn-missing-trans-opt-files",	warn_missing_trans_opt_files).
 long_option("warn-missing-trans-opt-deps",	warn_missing_trans_opt_deps).
 long_option("warn-simple-code",		warn_simple_code).
 long_option("warn-duplicate-calls",	warn_duplicate_calls).
@@ -1167,6 +1170,7 @@
 			warn_nothing_exported	-	bool(Enable),
 			warn_interface_imports	-	bool(Enable),
 			warn_missing_opt_files	-	bool(Enable),
+			warn_missing_trans_opt_files -	bool(Enable),
 			warn_missing_trans_opt_deps -	bool(Enable),
 			warn_simple_code	-	bool(Enable),
 			warn_missing_module_name -	bool(Enable),
@@ -1419,6 +1423,9 @@
 		"\twhich are not used in the interface.",
 		"--no-warn-missing-opt-files",
 		"\tDisable warnings about `.opt' files which cannot be opened.",
+		"--warn-missing-trans-opt-files",
+		"\tEnable warnings about `.trans_opt' files which cannot",
+		"\tbe opened.",
 		"--no-warn-missing-trans-opt-deps",
 		"\tDisable warnings produced when the information required",
 		"\tto allow `.trans_opt' files to be read when creating other",
Index: compiler/trans_opt.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/trans_opt.m,v
retrieving revision 1.13
diff -u -u -r1.13 trans_opt.m
--- trans_opt.m	1999/10/14 06:11:58	1.13
+++ trans_opt.m	1999/11/12 01:58:34
@@ -70,7 +70,7 @@
 
 :- implementation.
 
-:- import_module hlds_pred, mercury_to_mercury.
+:- import_module intermod, hlds_pred, mercury_to_mercury.
 :- import_module prog_io, globals, code_util.
 :- import_module passes_aux, prog_out, options, termination.
 
@@ -218,23 +218,9 @@
 
 	maybe_write_string(VeryVerbose, " done.\n"),
 
-	update_error_status(ModuleError, Messages, Error0, Error1),
+	intermod__update_error_status(trans_opt, FileName, ModuleError,
+		Messages, Error0, Error1),
+
 	{ list__append(Items0, Items1, Items2) },
 	read_trans_opt_files(Imports, Items2, Items, Error1, Error).
 
-:- pred update_error_status(module_error, message_list, 
-	bool, bool, io__state, io__state).
-:- mode update_error_status(in, in, in, out, di, uo) is det.
-
-update_error_status(ModuleError, Messages, Error0, Error1) -->
-	(
-		{ ModuleError = no },
-		{ Error1 = Error0 }
-	;
-		{ ModuleError = yes },
-		prog_out__write_messages(Messages),
-		{ Error1 = yes }
-	;
-		{ ModuleError = fatal },
-		{ Error1 = yes }	
-	).
Index: doc/user_guide.texi
===================================================================
RCS file: /home/staff/zs/imp/mercury/doc/user_guide.texi,v
retrieving revision 1.191
diff -u -u -r1.191 user_guide.texi
--- user_guide.texi	1999/11/04 07:35:22	1.191
+++ user_guide.texi	1999/11/12 03:57:19
@@ -2490,6 +2490,10 @@
 Warn about @samp{.opt} files that cannot be opened.
 
 @sp 1
+ at item --warn-missing-trans-opt-files
+Warn about @samp{.trans_opt} files that cannot be opened.
+
+ at sp 1
 @item --warn-non-stratification
 Warn about possible non-stratification of the predicates/functions in the
 module.
Index: tests/valid/Mmakefile
===================================================================
RCS file: /home/staff/zs/imp/tests/valid/Mmakefile,v
retrieving revision 1.47
diff -u -u -r1.47 Mmakefile
--- Mmakefile	1999/11/11 23:18:36	1.47
+++ Mmakefile	1999/11/12 03:59:09
@@ -62,6 +62,7 @@
 	int64.m \
 	intermod_impure.m \
 	intermod_lambda.m \
+	intermod_nested_module.m \
 	intermod_nested_uniq.m \
 	intermod_quote.m \
 	intermod_test.m \
@@ -184,6 +185,8 @@
 MCFLAGS-intermod_impure2	= --intermodule-optimization
 MCFLAGS-intermod_lambda		= --intermodule-optimization
 MCFLAGS-intermod_lambda2	= --intermodule-optimization
+MCFLAGS-intermod_nested_module	= --intermodule-optimization
+MCFLAGS-intermod_nested_module2	= --intermodule-optimization
 MCFLAGS-intermod_nested_uniq	= --intermodule-optimization
 MCFLAGS-intermod_nested_uniq2	= --intermodule-optimization
 MCFLAGS-intermod_quote		= --intermodule-optimization
@@ -201,6 +204,9 @@
 MCFLAGS-uniq_mode_inf_bug	= --infer-all
 MCFLAGS-vn_float		= -O5
 MCFLAGS-zero_arity		= --infer-modes
+
+# XXX mmake should automatically handle this dependency.
+intermod_nested_module2.date: intermod_nested_module2.date0
 
 check:	objs aditi_update.err
 
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list