[m-dev.] diff: MLDS back-end: fix Mmake --intermod-opt problem

Fergus Henderson fjh at cs.mu.OZ.AU
Wed May 17 07:13:14 AEST 2000


Estimated hours taken: 5

Fix a problem with the Mmake dependencies generated for the MLDS
back-end that broke intermodule optimization.

The problem was that the generated dependencies weren't taking
dependencies via `.opt' files into account.

compiler/modules.m:
	Change write_dependency_file so that takes AllDeps (which is
	used to calculate header file dependencies for the MLDS back-end)
	as an extra argument, rather than computing it here from the
	direct and indirect dependencies.  This allows AllDeps to
	include dependencies from `.opt' and `.trans_opt' files,
	rather than just those from the `.int*' files.
	Change generate_dependencies and generate_dependencies_write_d_files
	to compute AllDeps.  When generating dependencies, we don't
	know exactly which modules the `.opt' files will depend on, so
	the value computed here is a conservative (over-)aproximation.
	It doesn't matter much though, since the `.d' file will get
	rewritten every time the module is compiled, and the value
	for AllDeps computed then by mercury_compile.m will be exact,
	since the value is computed from the module_info after the
	`.opt' files have been read in.

compiler/ml_code_gen.m:
compiler/hlds_module.m:
	Move most of the code from ml_gen_imports (in ml_code_gen.m)
	to a new predicate module_info_get_all_deps (in hlds_module.m),
	for use by mercury_compile.m.

compiler/mercury_compile.m:
	Call module_info_get_all_deps, and pass the result of that
	to write_dependency_file.  This required changing things so that
	the `.d' file is only written after the initial HLDS is created.

Workspace: /home/pgrad/fjh/ws/hg
Index: compiler/hlds_module.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_module.m,v
retrieving revision 1.55
diff -u -d -r1.55 hlds_module.m
--- compiler/hlds_module.m	2000/05/13 13:56:09	1.55
+++ compiler/hlds_module.m	2000/05/16 18:22:55
@@ -224,6 +224,12 @@
 		set(module_specifier)).
 :- mode module_info_get_indirectly_imported_module_specifiers(in, out) is det.
 
+	% This returns all the modules that this module's code depends on,
+	% i.e. all modules that have been used or imported by this module,
+	% directly or indirectly, including parent modules.
+:- pred module_info_get_all_deps(module_info, set(module_name)).
+:- mode module_info_get_all_deps(in, out) is det.
+
 %-----------------------------------------------------------------------------%
 
 :- pred module_info_name(module_info, module_name).
@@ -789,6 +795,15 @@
 	module_info_ctors(ModuleInfo6, Ctors0),
 	map__optimize(Ctors0, Ctors),
 	module_info_set_ctors(ModuleInfo6, Ctors, ModuleInfo).
+
+module_info_get_all_deps(ModuleInfo, AllImports) :-
+	module_info_name(ModuleInfo, ModuleName),
+	get_ancestors(ModuleName, Parents),
+	module_info_get_imported_module_specifiers(ModuleInfo, DirectImports),
+	module_info_get_indirectly_imported_module_specifiers(ModuleInfo,
+		IndirectImports),
+	AllImports = (IndirectImports `set__union` DirectImports)
+			`set__union` set__list_to_set(Parents).
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
Index: compiler/mercury_compile.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.162
diff -u -d -r1.162 mercury_compile.m
--- compiler/mercury_compile.m	2000/05/13 09:44:23	1.162
+++ compiler/mercury_compile.m	2000/05/16 18:28:08
@@ -501,8 +501,7 @@
 		% we cant be creating the .trans_opt file.
 		{ MaybeTransOptDeps = no }
 	;
-		maybe_read_dependency_file(Module, MaybeTransOptDeps),
-		write_dependency_file(ModuleImports0, MaybeTransOptDeps)
+		maybe_read_dependency_file(Module, MaybeTransOptDeps)
 	),
 
 	% Errors in .opt and .trans_opt files result in software errors.
@@ -524,6 +523,14 @@
 	{ bool__or(UndefModes0, UndefModes2, UndefModes) },
 
 	mercury_compile__maybe_dump_hlds(HLDS0, "01", "initial"),
+
+	( { DontWriteDFile = yes } ->
+		[]
+	;
+		{ module_info_get_all_deps(HLDS0, AllDeps) },
+		write_dependency_file(ModuleImports0, AllDeps,
+			MaybeTransOptDeps)
+	),
 
 	% Only stop on syntax errors in .opt files.
 	( { FoundError = yes ; IntermodError = yes } ->
Index: compiler/ml_code_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_code_gen.m,v
retrieving revision 1.42
diff -u -d -r1.42 ml_code_gen.m
--- compiler/ml_code_gen.m	2000/05/15 17:31:26	1.42
+++ compiler/ml_code_gen.m	2000/05/16 20:25:25
@@ -701,13 +701,7 @@
 :- mode ml_gen_imports(in, out) is det.
 
 ml_gen_imports(ModuleInfo, MLDS_ImportList) :-
-	module_info_name(ModuleInfo, ModuleName),
-	get_ancestors(ModuleName, Parents),
-	module_info_get_imported_module_specifiers(ModuleInfo, DirectImports),
-	module_info_get_indirectly_imported_module_specifiers(ModuleInfo,
-		IndirectImports),
-	AllImports = (IndirectImports `set__union` DirectImports)
-			`set__union` set__list_to_set(Parents),
+	module_info_get_all_deps(ModuleInfo, AllImports),
 	MLDS_ImportList = list__map(mercury_module_name_to_mlds,
 		set__to_sorted_list(AllImports)).
 
Index: compiler/modules.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modules.m,v
retrieving revision 1.122
diff -u -d -r1.122 modules.m
--- compiler/modules.m	2000/05/15 17:31:28	1.122
+++ compiler/modules.m	2000/05/16 20:31:53
@@ -40,7 +40,7 @@
 :- interface.
 
 :- import_module prog_data, prog_io.
-:- import_module std_util, bool, list, io.
+:- import_module std_util, bool, list, set, io.
 
 %-----------------------------------------------------------------------------%
 
@@ -386,16 +386,21 @@
 
 %-----------------------------------------------------------------------------%
 
-	% write_dependency_file(Module, MaybeTransOptDeps):
+	% write_dependency_file(Module, AllDeps, MaybeTransOptDeps):
 	%	Write out the per-module makefile dependencies (`.d') file
 	%	for the specified module.
+	%	AllDeps is the set of all module names which the generated
+	%	code for this module might depend on, i.e. all that have been
+	%	used or imported, directly or indirectly, into this module,
+	%	including via .opt or .trans_opt files, and including
+	%	parent modules of nested modules.
 	%	MaybeTransOptDeps is a list of module names which the
 	%	`.trans_opt' file may depend on.  This is set to `no' if the
 	%	dependency list is not available.
 	%
-:- pred write_dependency_file(module_imports, maybe(list(module_name)),
-				io__state, io__state).
-:- mode write_dependency_file(in, in, di, uo) is det.
+:- pred write_dependency_file(module_imports, set(module_name),
+		maybe(list(module_name)), io__state, io__state).
+:- mode write_dependency_file(in, in, in, di, uo) is det.
 
 	%	maybe_read_dependency_file(ModuleName, MaybeTransOptDeps).
 	%	If transitive intermodule optimization has been enabled,
@@ -488,7 +493,7 @@
 :- import_module llds_out, passes_aux, prog_out, prog_util, mercury_to_mercury.
 :- import_module prog_io_util, globals, options, module_qual.
 
-:- import_module string, set, map, term, varset, dir, library.
+:- import_module string, map, term, varset, dir, library.
 :- import_module assoc_list, relation, char, require.
 :- import_module getopt, term, varset.
 
@@ -1215,7 +1220,7 @@
 	process_module_long_interfaces(ImpUsedModules, ".int",
 		ImpIndirectImports1, ImpIndirectImports, Module9, Module10),
 
-		% Process the short interfaces for indireclty imported modules.
+		% Process the short interfaces for indirectly imported modules.
 		% The short interfaces are treated as if
 		% they are imported using `use_module'.
 	{ append_pseudo_decl(Module10, used(interface), Module11) },
@@ -1525,7 +1530,7 @@
 
 %-----------------------------------------------------------------------------%
 
-write_dependency_file(Module, MaybeTransOptDeps) -->
+write_dependency_file(Module, AllDepsSet, MaybeTransOptDeps) -->
 	{ Module = module_imports(SourceFileName, ModuleName, ParentDeps,
 			IntDeps, ImplDeps, IndirectDeps, _InclDeps, FactDeps0,
 			_Items, _Error) },
@@ -1558,14 +1563,11 @@
 	; { Result = ok(DepStream) },
 		{ list__append(IntDeps, ImplDeps, LongDeps0) },
 		{ ShortDeps0 = IndirectDeps },
-		{ set__list_to_set(ParentDeps, ParentDepsSet) },
 		{ set__list_to_set(LongDeps0, LongDepsSet0) },
 		{ set__delete(LongDepsSet0, ModuleName, LongDepsSet) },
 		{ set__list_to_set(ShortDeps0, ShortDepsSet0) },
 		{ set__difference(ShortDepsSet0, LongDepsSet, ShortDepsSet1) },
 		{ set__delete(ShortDepsSet1, ModuleName, ShortDepsSet) },
-		{ AllDepsSet = (ShortDepsSet `set__union` LongDepsSet)
-			`set__union` ParentDepsSet },
 		{ set__to_sorted_list(LongDepsSet, LongDeps) },
 		{ set__to_sorted_list(ShortDepsSet, ShortDeps) },
 		{ set__to_sorted_list(AllDepsSet, AllDeps) },
@@ -2182,9 +2184,21 @@
 		{ relation__compose(ImplDepsRel, TransIntDepsRel,
 			IndirectDepsRel) },
 
+		%
+		% Compute the indirect optimization dependencies: indirect
+		% dependencies including those via `.opt' or `.trans_opt' files.
+		% Actually we can't compute that, since we don't know
+		% which modules the `.opt' files will import!
+		% Instead, we need to make a conservative (over-)approximation,
+		% and assume that the each module's `.opt' file might import any
+		% of that module's implementation dependencies; in actual fact,
+		% it will be some subset of that.
+		%
+		{ relation__tc(ImplDepsRel, IndirectOptDepsRel) },
+
 		generate_dependencies_write_d_files(DepsList,
 			IntDepsRel, ImplDepsRel, IndirectDepsRel,
-			TransOptDepsOrdering, DepsMap)
+			IndirectOptDepsRel, TransOptDepsOrdering, DepsMap)
 	).
 
 :- pred maybe_output_module_order(module_name::in, list(set(module_name))::in,
@@ -2223,20 +2237,28 @@
 	io__write_list(Stream, SCC, "\n", prog_out__write_sym_name).
 
 
-% generate_dependencies_write_d_files(Modules, IntDepsRel, TransOptOrder,
+% generate_dependencies_write_d_files(Modules, IntDepsRel, ImplDepsRel,
+%	IndirectDepsRel, IndirectOptDepsRel, TransOptOrder,
 %	DepsMap, IO0, IO):
 %		This predicate writes out the .d files for all the modules
 %		in the Modules list.  
-%		IntDepsRel gives the interface dependency relation
-%		(computed from the DepsMap).
+%		IntDepsRel gives the interface dependency relation.
+%		ImplDepsRel gives the implementation dependency relation
+%		IndirectDepsRel gives the indirect dependency relation
+%		(this includes dependencies on `*.int2' files).
+%		IndirectOptDepsRel gives the indirect optimization
+%		dependencies (this includes dependencies via `.opt'
+%		and `.trans_opt' files).
+%		These are all computed from the DepsMap.
 %		TransOptOrder gives the ordering that is used to determine
 %		which other modules the .trans_opt files may depend on.
 :- pred generate_dependencies_write_d_files(list(deps)::in, 
-	deps_rel::in, deps_rel::in, deps_rel::in, list(module_name)::in,
-	deps_map::in, io__state::di, io__state::uo) is det.
-generate_dependencies_write_d_files([], _, _, _, _, _) --> [].
+	deps_rel::in, deps_rel::in, deps_rel::in, deps_rel::in,
+	list(module_name)::in, deps_map::in,
+	io__state::di, io__state::uo) is det.
+generate_dependencies_write_d_files([], _, _, _, _, _, _) --> [].
 generate_dependencies_write_d_files([Dep | Deps],
-		IntDepsRel, ImplDepsRel, IndirectDepsRel,
+		IntDepsRel, ImplDepsRel, IndirectDepsRel, IndirectOptDepsRel,
 		TransOptOrder, DepsMap) --> 
 	{ Dep = deps(_, Module0) },
 
@@ -2250,6 +2272,8 @@
 	{ get_dependencies_from_relation(ImplDepsRel, ModuleName, ImplDeps) },
 	{ get_dependencies_from_relation(IndirectDepsRel, ModuleName,
 			IndirectDeps) },
+	{ get_dependencies_from_relation(IndirectOptDepsRel, ModuleName,
+			IndirectOptDeps) },
 	{ module_imports_set_int_deps(Module0, IntDeps, Module1) },
 	{ module_imports_set_impl_deps(Module1, ImplDeps, Module2) },
 	{ module_imports_set_indirect_deps(Module2, IndirectDeps, Module) },
@@ -2276,12 +2300,13 @@
 	% though it probably contains incorrect information.
 	{ module_imports_get_error(Module, Error) },
 	( { Error \= fatal } ->
-		write_dependency_file(Module, yes(TransOptDeps))
+		write_dependency_file(Module,
+			set__list_to_set(IndirectOptDeps), yes(TransOptDeps))
 	;
 		[]
 	),
 	generate_dependencies_write_d_files(Deps,
-		IntDepsRel, ImplDepsRel, IndirectDepsRel,
+		IntDepsRel, ImplDepsRel, IndirectDepsRel, IndirectOptDepsRel,
 		TransOptOrder, DepsMap).
 
 :- pred get_dependencies_from_relation(deps_rel, module_name,

-- 
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.
--------------------------------------------------------------------------
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