mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-16 01:43:35 +00:00
compiler/error_msg_inst.m:
When prettyprinting insts for use in error messages, we have to be careful
to generate finite output even for recursive insts. Previously, we did
the required check when processing user-defined inst names, but not when
processing compiler-generated inst names, which can also be recursive.
Fix this bug, which is Mantis bug 415.
Previously, we passed information about what potentially-recursive inst
names we have seen so far only downward. With the fix above, this avoids
infinite loops, but in some cases, it leads us to print the definition
of a given named inst more than once. Change our approach so that we
now pass information about the set of potentially-recursive inst names
we have seen sideways as well. This can make us generate more compact
and therefore more understandable output when prettyprinting insts that
contain such non-nested duplication.
When printing something that says "inst name x, which expands to ...",
indent the "..." one level deeper than the "inst name x". This visually
separates the thing being defined and its definition.
When prettyprinting complex insts, we show their structure using
indentation levels in the output. Each increase of indentation
should be balanced by a later matching decrease. Move the code that
does the increase and the decrease next to each other, to make it easier
to see the implicit correctness argument.
tests/invalid/bug415.{m,err_exp}:
A new test case for this bug.
tests/invalid/Mmakefile:
Enable the new test case.
tests/invalid/bug117.err_exp:
tests/invalid/bug191.err_exp:
tests/invalid/constrained_poly_insts2.err_exp:
tests/invalid/merge_ground_any.err_exp:
tests/invalid/polymorphic_unification.err_exp:
Expect the extra level of indentation after "which expands to".
tests/invalid/ho_default_func_4.err_exp:
Expect the extra level of indentation after "which expands to",
and expect a repeated inst name NOT to have its definition repeated.
64 lines
1.9 KiB
Mathematica
64 lines
1.9 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
|
|
%---------------------------------------------------------------------------%
|
|
%
|
|
% Compiling this module with
|
|
%
|
|
% $ mmc -C bug415.m
|
|
%
|
|
% used to generate a segmentation fault. The cause was a stack overflow
|
|
% from an infinite loop, which occurred when trying to convert a recursive
|
|
% $merge_inst to a list of format_components.
|
|
|
|
:- module bug415.
|
|
:- interface.
|
|
|
|
:- import_module list.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- pred ip_chunk(list(T)::in(list(I)), int::in, list(list(T))::out(list(I)))
|
|
is det.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module int.
|
|
:- import_module require.
|
|
|
|
ip_chunk(List, ChunkSize, ListOfSmallLists) :-
|
|
ip_chunk_2(List, ChunkSize, [], ChunkSize, ListOfSmallLists).
|
|
|
|
:- pred ip_chunk_2(list(T)::in(list(I)), int::in, list(T)::in(list(I)),
|
|
int::in, list(list(T))::out(list(I))) is det.
|
|
|
|
ip_chunk_2([], _ChunkSize, List0, _N, Lists) :-
|
|
(
|
|
List0 = [],
|
|
Lists = []
|
|
;
|
|
List0 = [_ | _],
|
|
ip_reverse(List0, List),
|
|
Lists = [List]
|
|
).
|
|
ip_chunk_2([X | Xs], ChunkSize, List0, N, Lists) :-
|
|
( if N > 1 then
|
|
ip_chunk_2(Xs, ChunkSize, [X | List0], N - 1, Lists)
|
|
else
|
|
ip_reverse([X | List0], List),
|
|
ip_chunk_2(Xs, ChunkSize, [], ChunkSize, ListsTail),
|
|
Lists = [List | ListsTail]
|
|
).
|
|
|
|
:- pred ip_reverse(list(T), list(T)).
|
|
:- mode ip_reverse(in(list(I)), out(list(I))) is det.
|
|
|
|
ip_reverse(List, RevList) :-
|
|
RevList = list.inst_preserving_reverse(List).
|
|
|
|
%---------------------------------------------------------------------------%
|
|
:- end_module bug415.
|
|
%---------------------------------------------------------------------------%
|