[m-rev.] for review: fix problem with parallel mmc --make and --rebuild

Peter Wang wangp at students.csse.unimelb.edu.au
Mon Aug 27 13:45:27 AEST 2007


Estimated hours taken: 2
Branches: main

In parallel mmc --make, disable the effect of `--rebuild' during the second
sequential pass over a list of target files (when we are just reading in file
timestamps), otherwise all the target files will be rebuilt a second time.

compiler/make.util.m:
	Make the fix above.

compiler/make.m:
compiler/make.program_target.m:
compiler/make.module_dep_file.m:
	Rename the field `rebuild_dependencies' in the `make_info' type to
	`rebuild_module_deps' to avoid confusion with the `--rebuild' option.
	Give it a distinct type instead of bool.

	Rename `RebuildDeps' everywhere to `RebuildModuleDeps'.

Index: ./compiler/make.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/make.m,v
retrieving revision 1.49
diff -u -r1.49 make.m
--- ./compiler/make.m	17 Aug 2007 02:04:13 -0000	1.49
+++ ./compiler/make.m	27 Aug 2007 03:37:16 -0000
@@ -45,6 +45,10 @@
 
 :- type make_info.
 
+:- type rebuild_module_deps
+    --->    do_rebuild_module_deps
+    ;       do_not_rebuild_module_deps.
+
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
@@ -116,7 +120,7 @@
 
                 % Should the `.module_dep' files be rebuilt.
                 % Set to `no' for `mmc --make clean'.
-                rebuild_dependencies    :: bool,
+                rebuild_module_deps     :: rebuild_module_deps,
 
                 keep_going              :: bool,
 
@@ -298,13 +302,13 @@
         list.map(classify_target(Globals), NonDependTargets,
             ClassifiedTargets),
 
-        ShouldRebuildDeps = yes,
+        ShouldRebuildModuleDeps = do_rebuild_module_deps,
         globals.io_lookup_int_option(analysis_repeat, AnalysisRepeat, !IO),
         MakeInfo0 = make_info(map.init, map.init, OptionArgs, Variables,
             map.init,
             init_cached_direct_imports,
             init_cached_transitive_dependencies,
-            ShouldRebuildDeps, KeepGoing,
+            ShouldRebuildModuleDeps, KeepGoing,
             set.init, no, set.list_to_set(ClassifiedTargets),
             AnalysisRepeat),
 
Index: ./compiler/make.util.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/make.util.m,v
retrieving revision 1.49
diff -u -r1.49 make.util.m
--- ./compiler/make.util.m	17 Aug 2007 02:04:13 -0000	1.49
+++ ./compiler/make.util.m	27 Aug 2007 03:37:16 -0000
@@ -64,8 +64,9 @@
     % concurrently, in any order, and multiple times.
     %
 :- pred foldl2_maybe_stop_at_error_maybe_parallel(bool::in,
-    foldl2_pred_with_status(T, Info, io)::in(foldl2_pred_with_status),
-    list(T)::in, bool::out, Info::in, Info::out, io::di, io::uo) is det.
+    foldl2_pred_with_status(T, make_info, io)::in(foldl2_pred_with_status),
+    list(T)::in, bool::out, make_info::in, make_info::out, io::di, io::uo)
+    is det.
 
 %-----------------------------------------------------------------------------%
 
@@ -305,9 +306,11 @@
 :- import_module transform_hlds.
 :- import_module transform_hlds.mmc_analysis.
 
+:- import_module bool.
 :- import_module char.
 :- import_module dir.
 :- import_module exception.
+:- import_module getopt_io.
 :- import_module set.
 :- import_module thread.
 :- import_module thread.channel.
@@ -420,8 +423,12 @@
     % Second pass (sequential).
     (
         Success0 = yes,
+        % Disable the `--rebuild' option during the sequential pass.
+        globals.io_lookup_bool_option(rebuild, Rebuild, !IO),
+        globals.io_set_option(rebuild, bool(no), !IO),
         foldl2_maybe_stop_at_error(KeepGoing, MakeTarget, Targets, Success,
-            !Info, !IO)
+            !Info, !IO),
+        globals.io_set_option(rebuild, bool(Rebuild), !IO)
     ;
         Success0 = no,
         Success = no
Index: ./compiler/make.program_target.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/make.program_target.m,v
retrieving revision 1.77
diff -u -r1.77 make.program_target.m
--- ./compiler/make.program_target.m	14 Jul 2007 02:32:44 -0000	1.77
+++ ./compiler/make.program_target.m	27 Aug 2007 03:37:17 -0000
@@ -597,20 +597,20 @@
 
 make_misc_target_builder(MainModuleName - TargetType, _, Succeeded,
         !Info, !IO) :-
-    % Don't rebuild dependencies when cleaning up.
-    RebuildDeps = !.Info ^ rebuild_dependencies,
+    % Don't rebuild .module_dep files when cleaning up.
+    RebuildModuleDeps = !.Info ^ rebuild_module_deps,
     (
         ( TargetType = misc_target_clean
         ; TargetType = misc_target_realclean
         )
     ->
-        !:Info = !.Info ^ rebuild_dependencies := no
+        !:Info = !.Info ^ rebuild_module_deps := do_not_rebuild_module_deps
     ;
         true
     ),
     find_reachable_local_modules(MainModuleName, Succeeded0, AllModulesSet,
         !Info, !IO),
-    !:Info = !.Info ^ rebuild_dependencies := RebuildDeps,
+    !:Info = !.Info ^ rebuild_module_deps := RebuildModuleDeps,
     AllModules = set.to_sorted_list(AllModulesSet),
     (
         TargetType = misc_target_clean,
Index: ./compiler/make.module_dep_file.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/make.module_dep_file.m,v
retrieving revision 1.29
diff -u -r1.29 make.module_dep_file.m
--- ./compiler/make.module_dep_file.m	2 May 2007 04:45:04 -0000	1.29
+++ ./compiler/make.module_dep_file.m	27 Aug 2007 03:37:17 -0000
@@ -57,9 +57,9 @@
 %-----------------------------------------------------------------------------%
 
 get_module_dependencies(ModuleName, MaybeImports, !Info, !IO) :-
-    RebuildDeps = !.Info ^ rebuild_dependencies,
+    RebuildModuleDeps = !.Info ^ rebuild_module_deps,
     ( ModuleName = unqualified(_) ->
-        maybe_get_module_dependencies(RebuildDeps, ModuleName,
+        maybe_get_module_dependencies(RebuildModuleDeps, ModuleName,
             MaybeImports, !Info, !IO)
     ; map.search(!.Info ^ module_dependencies, ModuleName, MaybeImports0) ->
         MaybeImports = MaybeImports0
@@ -73,7 +73,7 @@
         % dependencies.
         %
         Ancestors = get_ancestors(ModuleName),
-        list.foldl3(generate_ancestor_dependencies(RebuildDeps),
+        list.foldl3(generate_ancestor_dependencies(RebuildModuleDeps),
             Ancestors, no, Error, !Info, !IO),
         (
             Error = yes,
@@ -82,20 +82,20 @@
                 ^ elem(ModuleName) := MaybeImports
         ;
             Error = no,
-            maybe_get_module_dependencies(RebuildDeps,
+            maybe_get_module_dependencies(RebuildModuleDeps,
                 ModuleName, MaybeImports, !Info, !IO)
         )
     ).
 
-:- pred generate_ancestor_dependencies(bool::in, module_name::in,
-    bool::in, bool::out, make_info::in, make_info::out,
+:- pred generate_ancestor_dependencies(rebuild_module_deps::in,
+    module_name::in, bool::in, bool::out, make_info::in, make_info::out,
     io::di, io::uo) is det.
 
 generate_ancestor_dependencies(_, ModuleName, yes, yes, Info,
         Info ^ module_dependencies ^ elem(ModuleName) := no, !IO).
-generate_ancestor_dependencies(RebuildDeps, ModuleName, no, Error,
+generate_ancestor_dependencies(RebuildModuleDeps, ModuleName, no, Error,
         !Info, !IO) :-
-    maybe_get_module_dependencies(RebuildDeps, ModuleName, MaybeImports,
+    maybe_get_module_dependencies(RebuildModuleDeps, ModuleName, MaybeImports,
         !Info, !IO),
     (
         MaybeImports = yes(_),
@@ -105,25 +105,25 @@
         Error = yes
     ).
 
-:- pred maybe_get_module_dependencies(bool::in, module_name::in,
-    maybe(module_imports)::out, make_info::in, make_info::out,
+:- pred maybe_get_module_dependencies(rebuild_module_deps::in,
+    module_name::in, maybe(module_imports)::out, make_info::in, make_info::out,
     io::di, io::uo) is det.
 
-maybe_get_module_dependencies(RebuildDeps, ModuleName, MaybeImports,
+maybe_get_module_dependencies(RebuildModuleDeps, ModuleName, MaybeImports,
         !Info, !IO) :-
     ( map.search(!.Info ^ module_dependencies, ModuleName, MaybeImports0) ->
         MaybeImports = MaybeImports0
     ;
-        do_get_module_dependencies(RebuildDeps, ModuleName,
+        do_get_module_dependencies(RebuildModuleDeps, ModuleName,
             MaybeImports, !Info, !IO)
     ).
 
-:- pred do_get_module_dependencies(bool::in, module_name::in,
+:- pred do_get_module_dependencies(rebuild_module_deps::in, module_name::in,
     maybe(module_imports)::out, make_info::in, make_info::out,
     io::di, io::uo) is det.
 
-do_get_module_dependencies(RebuildDeps, ModuleName, !:MaybeImports, !Info,
-        !IO) :-
+do_get_module_dependencies(RebuildModuleDeps, ModuleName, !:MaybeImports,
+        !Info, !IO) :-
     % We can't just use
     %   `get_target_timestamp(ModuleName - source, ..)'
     % because that could recursively call get_module_dependencies,
@@ -143,14 +143,14 @@
         MaybeSourceFileTimestamp = ok(SourceFileTimestamp),
         MaybeDepFileTimestamp = ok(DepFileTimestamp),
         (
-            ( RebuildDeps = no
+            ( RebuildModuleDeps = do_not_rebuild_module_deps
             ; compare((>), DepFileTimestamp, SourceFileTimestamp)
             )
         ->
             % Since the source file was found in this directory, don't
             % use module_dep files which might be for installed copies
             % of the module.
-            read_module_dependencies_no_search(RebuildDeps, ModuleName,
+            read_module_dependencies_no_search(RebuildModuleDeps, ModuleName,
                 !Info, !IO)
         ;
             make_module_dependencies(ModuleName, !Info, !IO)
@@ -158,7 +158,8 @@
     ;
         MaybeSourceFileTimestamp = error(_),
         MaybeDepFileTimestamp = ok(DepFileTimestamp),
-        read_module_dependencies_search(RebuildDeps, ModuleName, !Info, !IO),
+        read_module_dependencies_search(RebuildModuleDeps, ModuleName, !Info,
+            !IO),
 
         %
         % Check for the case where the module name doesn't match the
@@ -177,7 +178,7 @@
             (
                 MaybeSourceFileTimestamp1 = ok(SourceFileTimestamp1),
                 (
-                    ( RebuildDeps = no
+                    ( RebuildModuleDeps = do_not_rebuild_module_deps
                     ; compare((>), DepFileTimestamp, SourceFileTimestamp1)
                     )
                 ->
@@ -208,10 +209,10 @@
         % source file is in another directory.
         %
         (
-            RebuildDeps = yes,
+            RebuildModuleDeps = do_rebuild_module_deps,
             make_module_dependencies(ModuleName, !Info, !IO)
         ;
-            RebuildDeps = no,
+            RebuildModuleDeps = do_not_rebuild_module_deps,
             !:Info = !.Info ^ module_dependencies ^ elem(ModuleName) := no
         )
     ),
@@ -308,25 +309,28 @@
         io.set_exit_status(1, !IO)
     ).
 
-:- pred read_module_dependencies_search(bool::in, module_name::in,
-    make_info::in, make_info::out, io::di, io::uo) is det.
+:- pred read_module_dependencies_search(rebuild_module_deps::in,
+    module_name::in, make_info::in, make_info::out, io::di, io::uo) is det.
 
-read_module_dependencies_search(RebuildDeps, ModuleName, !Info, !IO) :-
+read_module_dependencies_search(RebuildModuleDeps, ModuleName, !Info, !IO) :-
     globals.io_lookup_accumulating_option(search_directories, SearchDirs, !IO),
-    read_module_dependencies_2(RebuildDeps, SearchDirs, ModuleName,
+    read_module_dependencies_2(RebuildModuleDeps, SearchDirs, ModuleName,
         !Info, !IO).
 
-:- pred read_module_dependencies_no_search(bool::in, module_name::in,
-    make_info::in, make_info::out, io::di, io::uo) is det.
+:- pred read_module_dependencies_no_search(rebuild_module_deps::in,
+    module_name::in, make_info::in, make_info::out, io::di, io::uo) is det.
 
-read_module_dependencies_no_search(RebuildDeps, ModuleName, !Info, !IO) :-
-    read_module_dependencies_2(RebuildDeps, [dir.this_directory], ModuleName,
-        !Info, !IO).
+read_module_dependencies_no_search(RebuildModuleDeps, ModuleName, !Info,
+        !IO) :-
+    read_module_dependencies_2(RebuildModuleDeps, [dir.this_directory],
+        ModuleName, !Info, !IO).
 
-:- pred read_module_dependencies_2(bool::in, list(dir_name)::in,
-    module_name::in, make_info::in, make_info::out, io::di, io::uo) is det.
+:- pred read_module_dependencies_2(rebuild_module_deps::in,
+    list(dir_name)::in, module_name::in, make_info::in, make_info::out,
+    io::di, io::uo) is det.
 
-read_module_dependencies_2(RebuildDeps, SearchDirs, ModuleName, !Info, !IO) :-
+read_module_dependencies_2(RebuildModuleDeps, SearchDirs, ModuleName, !Info,
+        !IO) :-
     module_name_to_search_file_name(ModuleName, make_module_dep_file_extension,
         ModuleDepFile, !IO),
     io.input_stream(OldInputStream, !IO),
@@ -451,8 +455,9 @@
             % (make_module_dependencies expects to be given the top-level
             % module in the source file).
             %
-            SubRebuildDeps = no,
-            list.foldl2(read_module_dependencies_2(SubRebuildDeps, SearchDirs),
+            SubRebuildModuleDeps = do_not_rebuild_module_deps,
+            list.foldl2(
+                read_module_dependencies_2(SubRebuildModuleDeps, SearchDirs),
                 NestedChildren, !Info, !IO),
             (
                 list.member(NestedChild, NestedChildren),
@@ -465,33 +470,35 @@
                     true
                 )
             ->
-                read_module_dependencies_remake(RebuildDeps, ModuleName,
+                read_module_dependencies_remake(RebuildModuleDeps, ModuleName,
                     "error in nested sub-modules", !Info, !IO)
             ;
                 true
             )
         ;
-            read_module_dependencies_remake(RebuildDeps, ModuleName,
+            read_module_dependencies_remake(RebuildModuleDeps, ModuleName,
                 "parse error", !Info, !IO)
         )
     ;
         SearchResult = error(_),
         % XXX should use the error message.
-        read_module_dependencies_remake(RebuildDeps, ModuleName,
+        read_module_dependencies_remake(RebuildModuleDeps, ModuleName,
             "couldn't find `.module_dep' file", !Info, !IO)
     ).
 
     % Something went wrong reading the dependencies, so just rebuild them.
-:- pred read_module_dependencies_remake(bool::in, module_name::in, string::in,
-    make_info::in, make_info::out, io::di, io::uo) is det.
+:- pred read_module_dependencies_remake(rebuild_module_deps::in,
+    module_name::in, string::in, make_info::in, make_info::out,
+    io::di, io::uo) is det.
 
-read_module_dependencies_remake(RebuildDeps, ModuleName, Msg, !Info, !IO) :-
+read_module_dependencies_remake(RebuildModuleDeps, ModuleName, Msg, !Info,
+        !IO) :-
     (
-        RebuildDeps = yes,
+        RebuildModuleDeps = do_rebuild_module_deps,
         debug_msg(read_module_dependencies_remake_msg(ModuleName, Msg), !IO),
         make_module_dependencies(ModuleName, !Info, !IO)
     ;
-        RebuildDeps = no
+        RebuildModuleDeps = do_not_rebuild_module_deps
     ).
 
 :- pred read_module_dependencies_remake_msg(module_name::in, string::in,
--------------------------------------------------------------------------
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