[m-rev.] for review: Reset target file timestamp cache before installing library grade.

Peter Wang novalazy at gmail.com
Tue Dec 12 14:39:48 AEDT 2023


When installing library grades with mmc --make, we change the grade and
enable the use of grade subdirs (if not already enabled) in the globals.
We must also clear the target file timestamp cache, as the information
it contains is only valid for a given grade and grade-subdir setting.

compiler/make.program_target.m:
    As above.

compiler/make.timestamp.m:
    Add an optional trace goal to check that a timestamp retrieved
    from the cache matches the actual timestamp of the file on disk.
---
 compiler/make.program_target.m |  5 +++++
 compiler/make.timestamp.m      | 35 ++++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/compiler/make.program_target.m b/compiler/make.program_target.m
index 385a07f2f..3a3144297 100644
--- a/compiler/make.program_target.m
+++ b/compiler/make.program_target.m
@@ -1847,6 +1847,11 @@ install_library_grade(LinkSucceeded0, ModuleName, AllModules,
         make_info_set_dep_file_status_map(StatusMap, !Info),
         make_info_set_option_args(OptionArgs, !Info),
 
+        % Reset the target file timestamp cache, as the information it contains
+        % is not valid for the changed grade and grade-subdir setting.
+        make_info_set_target_file_timestamps(init_target_file_timestamps,
+            !Info),
+
         % Building the library in the new grade is done in a separate process
         % to make it easier to stop and clean up on an interrupt.
         globals.lookup_bool_option(LibGlobals, very_verbose, VeryVerbose),
diff --git a/compiler/make.timestamp.m b/compiler/make.timestamp.m
index 494d54c7a..465636739 100644
--- a/compiler/make.timestamp.m
+++ b/compiler/make.timestamp.m
@@ -76,6 +76,7 @@
 
 :- import_module dir.
 :- import_module map.
+:- import_module require.
 :- import_module string.
 :- import_module version_hash_table.
 
@@ -133,6 +134,10 @@ get_target_timestamp(ProgressStream, Globals, Search, TargetFile,
             version_hash_table.search(TargetFileTimestamps0, TargetFile,
                 Timestamp)
         then
+            trace [compile_time(flag("target_timestamp_cache")), io(!TIO)] (
+                verify_cached_target_file_timestamp(ProgressStream, Globals,
+                    Search, TargetFile, Timestamp, !.Info, _Info, !TIO)
+            ),
             MaybeTimestamp = ok(Timestamp)
         else
             ForSearch = maybe_search_to_maybe_for_search(Search),
@@ -157,6 +162,36 @@ get_target_timestamp(ProgressStream, Globals, Search, TargetFile,
         )
     ).
 
+:- pred verify_cached_target_file_timestamp(io.text_output_stream::in,
+    globals::in, maybe_search::in, target_file::in, timestamp::in,
+    make_info::in, make_info::out, io::di, io::uo) is det.
+
+verify_cached_target_file_timestamp(ProgressStream, Globals, Search,
+        TargetFile, Timestamp0, !Info, !IO) :-
+    ForSearch = maybe_search_to_maybe_for_search(Search),
+    module_maybe_nested_target_file_to_file_name(ProgressStream,
+        Globals, $pred, ForSearch, TargetFile, FileName, !Info, !IO),
+    get_target_timestamp_2(ProgressStream, Globals,
+        Search, TargetFile, FileName, MaybeTimestamp, !Info, !IO),
+    (
+        MaybeTimestamp = ok(Timestamp),
+        ( if Timestamp0 \= Timestamp then
+            string.format(
+                "target file timestamp differs: %s (cached) vs %s (actual)",
+                [s(timestamp_to_string(Timestamp0)),
+                s(timestamp_to_string(Timestamp))], Msg),
+            unexpected($pred, Msg)
+        else
+            true
+        )
+    ;
+        MaybeTimestamp = error(Error),
+        string.format(
+            "target file timestamp differs: %s (cached) vs %s (actual)",
+            [s(timestamp_to_string(Timestamp0)), s(Error)], Msg),
+        unexpected($pred, Msg)
+    ).
+
     % Special treatment for `.analysis' files. If the corresponding
     % `.analysis_status' file says the `.analysis' file is invalid,
     % then we treat it as out of date.
-- 
2.42.0



More information about the reviews mailing list