[m-rev.] for post-commit review: maybe_written_specs

Julien Fischer jfischer at opturion.com
Tue Apr 28 15:23:57 AEST 2026


On Sun, 26 Apr 2026 at 16:45, Zoltan Somogyi <zoltan.somogyi at runbox.com> wrote:

> Provide a way to record already written specs.

...

> diff --git a/compiler/error_spec.m b/compiler/error_spec.m
> index 5b3e32b5e..b64e9e2f7 100644
> --- a/compiler/error_spec.m
> +++ b/compiler/error_spec.m

...

> @@ -89,6 +91,39 @@
>  :- func contains_errors_or_warnings_treated_as_errors_opt_table(option_table,
>      list(error_spec)) = bool.
>
> +%---------------------------------------------------------------------------%
> +
> +:- type maybe_written_spec
> +    --->    to_be_written_spec(error_spec)
> +    ;       already_written_spec(std_error_spec).
> +            % Sometimes we want to both
> +            %
> +            % - print an error_spec just after it is generated, and
> +            % - also return it to inform decisions about the presence
> +            %   of errors.
> +            %
> +            % To prevent the caller from writing out a duplicate copy
> +            % of the error_spec, we can return it wrapped up
> +            % in this function symbol, which
> +            %
> +            % - preserves its severity (for decisions),
> +            % - preserves its text (which may be helpful when debugging
> +            %   the code that makes those decision),

s/decision/decisions/

...

> diff --git a/compiler/write_error_spec.m b/compiler/write_error_spec.m
> index 63311d370..1a4bf9534 100644
> --- a/compiler/write_error_spec.m
> +++ b/compiler/write_error_spec.m

...

> @@ -245,6 +256,33 @@
>  :- import_module term_context.
>  :- import_module uint.
>
> +%---------------------------------------------------------------------------%
> +
> +write_not_yet_written_specs(Stream, Globals, !MaybeWrittenSpecs, !IO) :-
> +    categorize_maybe_written_specs(!.MaybeWrittenSpecs,
> +        [], AlreadyWritten0, [], ToBeWritten0),
> +    write_error_specs_return_std(Stream, Globals,
> +        ToBeWritten0, NowWrittenStd, !IO),
> +    NowWritten = list.map((func(S) = already_written_spec(S)), NowWrittenStd),
> +    !:MaybeWrittenSpecs = AlreadyWritten0 ++ NowWritten.
> +
> +:- pred categorize_maybe_written_specs(list(maybe_written_spec)::in,
> +    list(maybe_written_spec)::in, list(maybe_written_spec)::out,
> +    list(error_spec)::in, list(error_spec)::out) is det.
> +
> +categorize_maybe_written_specs([], !AlreadyWritten, !ToBeWritten).
> +categorize_maybe_written_specs([MaybeWritten | MaybeWrittens],
> +        !AlreadyWritten, !ToBeWritten) :-
> +    (
> +        MaybeWritten = already_written_spec(_StdSpec),
> +        !:AlreadyWritten = [MaybeWritten | !.AlreadyWritten]
> +    ;
> +        MaybeWritten = to_be_written_spec(Spec),
> +        !:ToBeWritten = [Spec | !.ToBeWritten]
> +    ),
> +    categorize_maybe_written_specs(MaybeWrittens,
> +        !AlreadyWritten, !ToBeWritten).
> +
>  %---------------------------------------------------------------------------%
>  %
>  % We keep a record of the set of already-printed verbose_once components
> @@ -256,24 +294,21 @@
>  % all its occrrences are generated in one pass. For pretty much all our passes,

Spelling there (existing problem).

The rest looks fine.

Julien.


More information about the reviews mailing list