[m-rev.] for review: check library install just once

Julien Fischer jfischer at opturion.com
Wed Jan 12 15:48:03 AEDT 2022


On Wed, 12 Jan 2022, Zoltan Somogyi wrote:

> Check library install just once.
> 
> compiler/mercury_compile_main.m:
>     Unless invoked by mmc --make, we used to check whether the Mercury
>     standard libraries are installed once per compiler argument.
>     This was wasteful, since the check involved two system calls.
>     Do this check just once, before starting to process the argument list.
>
>     Instead of testing whether we are invoked by mmc --make once per argument,
>     test it just once.
>
>     Invocations of mmc --make have always disregarded the setting
>     of --filename-from-stdin, always behaving as it were "no".
>     Do not let such invocations accidentally pass a globals structure
>     setting that option to "yes" to its sub-invocations of the compiler.
> 
> diff --git a/compiler/mercury_compile_main.m b/compiler/mercury_compile_main.m
> index 05ce0ae2d..4a48e494e 100644
> --- a/compiler/mercury_compile_main.m
> +++ b/compiler/mercury_compile_main.m

...

> @@ -835,19 +840,49 @@ do_op_mode_query(Globals, OpModeQuery, !IO) :-
>
>  do_op_mode_args(Globals, OpModeArgs, FileNamesFromStdin, DetectedGradeFlags,
>          OptionVariables, OptionArgs, Args, !HaveReadModuleMaps, !Specs, !IO) :-
> +    globals.lookup_bool_option(Globals, invoked_by_mmc_make, InvokedByMake),
>      (
>          FileNamesFromStdin = yes,
> +        % Mmc --make does not set --filenames-from-stdin.
> +        expect(unify(InvokedByMake, no), $pred, "InvokedByMake != no"),
>          io.stdin_stream(StdIn, !IO),
> -        process_compiler_stdin_args(Globals, StdIn, OpModeArgs,
> +        setup_and_process_compiler_stdin_args(Globals, StdIn, OpModeArgs,
>              DetectedGradeFlags, OptionVariables, OptionArgs,
>              cord.empty, ModulesToLinkCord, cord.empty, ExtraObjFilesCord,
>              !HaveReadModuleMaps, !Specs, !IO)
>      ;
>          FileNamesFromStdin = no,
> -        process_compiler_cmd_line_args(Globals, OpModeArgs,
> +        (
> +            InvokedByMake = no,
> +            % We used to do this check once per compiler arg, which was
> +            % quite wasteful.
> +            %
> +            % We also used to do this check, as we are we doing now,
> +            % only when InvokedByMake = no. I, zs, don't know why, though
> +            % I *guess* that it may be that the compiler invocation that *set*
> +            % --invoked-by-mmc-make may have done it already.

It may be because the library grade check was extended to work when compiling
single module programs using mmc directly, instead of just when using --make.
(From the looks of it that fact is not documented at the moment.)

The diff looks fine.

Julien.


More information about the reviews mailing list