[m-rev.] for review: parallel mmc --make and nested sub-modules

Peter Wang novalazy at gmail.com
Fri Sep 2 10:27:01 AEST 2011


Branches: main, 11.07

Fix problems with nested sub-modules and parallel mmc --make.

The interface and intermediate target files for nested sub-modules
are built as part of their parent modules.  In sequential mode, there is
no harm in trying to build those files separately, but with parallel
make, two processes may try to create the files from the same parent
module simultaneously.

compiler/make.dependencies.m:
	Add a predicate to remove nested modules from a list.

compiler/make.program_target.m:
	Remove nested modules from the list of intermediate targets to
	create.

	Remove nested modules from the list of interface files to create.

diff --git a/compiler/make.dependencies.m b/compiler/make.dependencies.m
index 3f30fd0..9bbf2bb 100644
--- a/compiler/make.dependencies.m
+++ b/compiler/make.dependencies.m
@@ -112,6 +112,12 @@
     set(module_name)::out, make_info::in, make_info::out,
     io::di, io::uo) is det.
 
+    % Remove all nested modules from a list of modules.
+    %
+:- pred remove_nested_modules(globals::in, list(module_name)::in,
+    list(module_name)::out, make_info::in, make_info::out, io::di, io::uo)
+    is det.
+
 %-----------------------------------------------------------------------------%
 
     % Find all modules in the current directory which are reachable (by import)
@@ -1255,6 +1261,26 @@ find_transitive_module_dependencies_2(KeepGoing, DependenciesType, ModuleLocn,
 
 %-----------------------------------------------------------------------------%
 
+remove_nested_modules(Globals, Modules0, Modules, !Info, !IO) :-
+    list.foldl3(collect_nested_modules(Globals), Modules0,
+        set.init, NestedModules, !Info, !IO),
+    list.negated_filter(set.contains(NestedModules), Modules0, Modules).
+
+:- pred collect_nested_modules(globals::in, module_name::in,
+    set(module_name)::in, set(module_name)::out, make_info::in, make_info::out,
+    io::di, io::uo) is det.
+
+collect_nested_modules(Globals, ModuleName, !NestedModules, !Info, !IO) :-
+    get_module_dependencies(Globals, ModuleName, MaybeImports, !Info, !IO),
+    (
+        MaybeImports = yes(Imports),
+        set.insert_list(Imports ^ mai_nested_children, !NestedModules)
+    ;
+        MaybeImports = no
+    ).
+
+%-----------------------------------------------------------------------------%
+
 make_local_module_id_options(Globals, ModuleName, Success, Options,
         !Info, !IO) :-
     find_reachable_local_modules(Globals, ModuleName, Success, LocalModules,
diff --git a/compiler/make.program_target.m b/compiler/make.program_target.m
index 7f1d5e1..dbc15c2 100644
--- a/compiler/make.program_target.m
+++ b/compiler/make.program_target.m
@@ -193,8 +193,10 @@ make_linked_target_2(LinkedTargetFile, Globals, _, Succeeded, !Info, !IO) :-
         get_target_modules(Globals, IntermediateTargetType, AllModulesList,
             ObjModulesAlpha, !Info, !IO),
         order_target_modules(Globals, ObjModulesAlpha, ObjModules, !Info, !IO),
-        IntermediateTargets = make_dependency_list(ObjModules,
-            IntermediateTargetType),
+        remove_nested_modules(Globals, ObjModules, ObjModulesNonnested, !Info,
+            !IO),
+        IntermediateTargetsNonnested =
+            make_dependency_list(ObjModulesNonnested, IntermediateTargetType),
         ObjTargets = make_dependency_list(ObjModules, ObjectTargetType),
 
         list.map_foldl2(get_foreign_object_targets(Globals, PIC),
@@ -211,7 +213,7 @@ make_linked_target_2(LinkedTargetFile, Globals, _, Succeeded, !Info, !IO) :-
             BuildDepsSucceeded = no
         ;
             foldl2_maybe_stop_at_error_maybe_parallel(KeepGoing,
-                make_module_target, Globals, IntermediateTargets,
+                make_module_target, Globals, IntermediateTargetsNonnested,
                 BuildDepsSucceeded0, !Info, !IO),
             (
                 BuildDepsSucceeded0 = yes,
@@ -908,19 +910,20 @@ make_misc_target_builder(MainModuleName - TargetType, Globals, _, Succeeded,
 :- pred make_all_interface_files(globals::in, list(module_name)::in, bool::out,
     make_info::in, make_info::out, io::di, io::uo) is det.
 
-make_all_interface_files(Globals, AllModules, Succeeded, !Info, !IO) :-
-    list.foldl3(collect_modules_with_children(Globals), AllModules,
+make_all_interface_files(Globals, AllModules0, Succeeded, !Info, !IO) :-
+    remove_nested_modules(Globals, AllModules0, NonnestedModules, !Info, !IO),
+    list.foldl3(collect_modules_with_children(Globals), NonnestedModules,
         [], ParentModules, !Info, !IO),
-    ShortInts = make_dependency_list(AllModules,
+    ShortInts = make_dependency_list(NonnestedModules,
         module_target_unqualified_short_interface),
     PrivateInts = make_dependency_list(ParentModules,
         module_target_private_interface),
-    LongInts = make_dependency_list(AllModules,
+    LongInts = make_dependency_list(NonnestedModules,
         module_target_long_interface),
     globals.get_any_intermod(Globals, AnyIntermod),
     (
         AnyIntermod = yes,
-        OptFiles = make_dependency_list(AllModules,
+        OptFiles = make_dependency_list(NonnestedModules,
             module_target_intermodule_interface)
     ;
         AnyIntermod = no,

--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list