[m-rev.] for review: standardize "reading file" messages

Julien Fischer jfischer at opturion.com
Fri Jan 21 14:20:02 AEDT 2022


On Fri, 21 Jan 2022, Zoltan Somogyi wrote:

> Standardize messages about reading files.
> 
> compiler/read_modules.m:
>     When reading in Mercury source files, interface files or optimization
>     files, we optionally generate progress messages of the form
>
>         % Reading module xyz... done.
>
>     But the form of these messages has not been consistent, so that
>     when reading .opt files, we got messages of the form
>
>         % Reading xyz.opt...
>         % Done.
>
>     And we sometimes got messages such as
>
>         % Reading .int file for module xyz.int... done.
>
>     This is mostly because responsibility for constructing these messages
>     has been dispersed; different parts of it were generated in different
>     places, and sometimes when one place switches to a new scheme, not all
>     the corresponding places where updated accordingly.
>
>     This diff changes that by constructing these messages in two predicates
>     (output_read_msg and output_read_done_msg) in this module, leaving to
>     callers only a choice between a set of four message forms.
>
>     To make this possible, move the read_module_{plain,trans}_opt predicates
>     here from grab_modules.m. Their equivalents for reading Mercury source
>     files and interface files were here already, so here is where they belong.
>
>     Add several "XXX CLEANUP" markers for future changes.
> 
> compiler/parse_module.m:
>     Do not expect callers to compute the filenames containing .opt
>     and .trans_opt files, since the code here already does that.
> 
> compiler/grab_modules.m:
>     Delete the predicates moved to read_modules.m (under new names, to fit in
>     with the predicates already there).
>
>     Delete some obsolete comments.
>
>     Fix some old variable names.
> 
> compiler/deps_map.m:
> compiler/generate_dep_d_files.m:
> compiler/make.module_dep_file.m:
> compiler/mercury_compile_main.m:
> compiler/recompilation.check.m:
> compiler/write_module_interface_files.m:
>     Conform to the changes above.

...

> diff --git a/compiler/read_modules.m b/compiler/read_modules.m
> index c99941dff..b65d69e48 100644
> --- a/compiler/read_modules.m
> +++ b/compiler/read_modules.m

...

> @@ -105,13 +105,31 @@
>              )
>      ;       tried_to_read_module_failed.
> 
> -%-----------------------------------------------------------------------------%
> +%---------------------------------------------------------------------------%
>
>  :- type maybe_ignore_errors
>      --->    ignore_errors
>      ;       do_not_ignore_errors.
> 
> -    % read_module_src(Globals, Descr, IgnoreErrors, Search,
> +    % Why are we attempting to read and parse a file?
> +:- type read_msg

Maybe name the type read_reason_msg or read_purpose_msg.


> +    --->    rm_file
> +            % Because the compiler has been asked to compile the named file
> +            % in some fashion. (This could be generating target code for it,
> +            % making its interface files, making its optimization files, etc.)
> +    ;       rm_std(module_name)
> +            % Because the named file belongs to this module (as a source file,
> +            % interface file, or optimization file), and the compiler has been
> +            % asked to compile that module in some fashion.
> +    ;       rm_old(module_name)
> +            % Because the named file belongs to this module, and we need
> +            % the old contents of the file (i.e. the current contents
> +            % that is about to be overwritten, if necessary).

That last bit isn't clear.


> +    ;       rm_get_deps(module_name).
> +            % Because the named file belongs to this module, and we need
> +            % to get its dependencies.
> +
> +    % read_module_src(Globals, ReadMsg, IgnoreErrors, Search,

...


> @@ -194,56 +212,90 @@

...

> -%-----------------------------------------------------------------------------%
> +    % read_module_{plain,trans}_opt(Globals, ModuleName, FileName,
> +    %   ParseTreeOpt, Specs, Errors, !IO):
> +    %
> +    % Given a module name, read in and parse the specified kind of optimization
> +    % file for that module, printing progress messages along the way
> +    % if the verbosity level calls for that.
> +    %
> +    % These predicates do a very similar job to read_module_intN,
> +    % but there are several differences.
> +    %
> +    % - We do not do anything with errors in .opt and .trans_opt files;
> +    %   we leave that up to the caller.
> +    %
> +    % - We do always do search for .opt and .trans_opt files, but
> +    %   in the directories named by the intermod_directories option, *not*
> +    %   in the directories named by the search_directories option.
> +    %
> +    % - None of our callers are ever interested in timestamps,
> +    %   from the module name, so these predicates do not search for the
> +    %   right filename either, but t

"but t"?

The rest looks fine.

Julien.


More information about the reviews mailing list