[m-dev.] request for opinions about a change to switch detection
Peter Wang
novalazy at gmail.com
Fri Nov 14 13:17:46 AEDT 2025
On Fri, 14 Nov 2025 12:29:54 +1100 Julien Fischer <jfischer at opturion.com> wrote:
> On Fri, 14 Nov 2025 at 10:50, Zoltan Somogyi <zoltan.somogyi at runbox.com> wrote:
>
> > I can fix the problem in several ways, and I am looking for opinions
> > on which you guys prefer.
> >
> > The first fix is to modify the code of switch detection to inline
> > any nested switches it now generates. This is conceptually simple,
> > but it can, in the worst case, greatly increase the workload of
> > the passes between switch detection and format call. This is because
> > inlining the inner switch in the outer switch creates N copies of
> > all the code that follows the inner switch in its arm of the outer
> > switch if the inner switch has N cases, and that following code has
> > no bound on its size.
> >
> > The second fix is to modify the code of the format_call pass
> > to inline switches. This avoids the potential slowdown described above,
> > but requires a new pass as the initial part of format_call. Since most
> > procedures do not contain any call to any predicate named "format",
> > this prepass would not slow down the compilation of most procedures;
> > its impact would mostly by on compiler code complexity.
> >
> > The third "fix" is to simply declare that the warning is an appropriate
> > response to code like the above.
>
> It is not an appropriate response to such code.
>
Why not? There is no description of how smart the compiler is supposed
to be to implement --warn-unknown-format-calls. I'm surprised the
compiler didn't warn about that code before. The fact that it didn't
in that particular case seems like an artefact of the implementation
more than by design.
The compiler does produce the warning for this predicate:
p(List, Str) :-
(
List = [],
Fmt = "empty %d"
;
List = [_ | _],
Fmt = "non-empty %d"
),
string.format(Fmt, [i(1)], Str).
I'm not saying the third option is the best, but I wouldn't simply
reject it.
Peter
More information about the developers
mailing list