[m-rev.] diff: factor out common code in error_msg_inst.m
Peter Wang
novalazy at gmail.com
Wed Aug 30 11:16:28 AEST 2023
On Wed, 30 Aug 2023 06:52:35 +1000 "Zoltan Somogyi" <zoltan.somogyi at runbox.com> wrote:
> This should not need review.
>
> Zoltan.
> Factor out common code in error_msg_inst.m.
>
> compiler/error_msg_inst.m:
> Most parts of this module consisted of pairs of predicates following
> the naming scheme X_to_pieces and X_to_inline_pieces. Replace each such
> pair of predicates with one predicate that takes a flag that says
> which version we want, since this allows us to avoid doing double
> maintenance. (The overall logic of the two versions was always the same;
> the differences affected only the construction of the piece sequence.)
>
> Get the compiler to recreate the original pair of procedures
> by using two separate specialized mode declarations to require
> the callers of each such predicate to specify whether they want
> to generate multi line or inline piece sequences.
> diff --git a/compiler/error_msg_inst.m b/compiler/error_msg_inst.m
> index 50493708e..9444798a2 100644
> --- a/compiler/error_msg_inst.m
> +++ b/compiler/error_msg_inst.m
...
> +:- pred inst_to_pieces(inst_msg_info, maybe_inline_pieces, mer_inst,
> + list(format_piece), list(format_piece), expansions_info, expansions_info).
> +:- mode inst_to_pieces(in, in(multi_line_pieces),
> + in, in, out, in, out) is det.
> +:- mode inst_to_pieces(in, in(inline_pieces),
> + in, in, out, in, out) is det.
I don't think there is any need to create two specialised procedures for
each of these predicates; testing the flag at runtime will do.
Peter
More information about the reviews
mailing list