Files
mercury/tests/valid/bug142.m
Peter Wang 24322faabc Work around bug #142. The symptom is an assertion failure in
Branches: main, 10.04

Work around bug #142.  The symptom is an assertion failure in
hlds.hlds_rtti.apply_substs_to_constraint_map.  It occurs when:

- a variable holding a typeclass_info is used multiple times in a call;
- the called procedure is inlined into the caller;
- the corresponding head variables have class constraints with functional
  dependencies;
- the type variables in those constraints should be unified, but type variables
  in the ranges of functional dependencies are not unified;
- a single typeclass_info variable ends up being for two different constraints.

The work around adopted here is to prevent inlining of a call when a single
typeclass_info variable appears multiple times in the argument list, for which
the head variables have differing class constraints.

compiler/inlining.m:
        As above.

tests/valid/Mercury.options:
tests/valid/Mmakefile:
tests/valid/bug142.m:
        Add test case.
2010-05-10 05:02:27 +00:00

54 lines
1.4 KiB
Mathematica

% Regression test for bug #142 (worked around in inlining.m)
%
% mmc --optimise-higher-order --inline-single-use -C bug142.m
% Uncaught Mercury exception:
% Software Error: hlds_rtti.m: Unexpected: inconsistent typeclass_infos
:- module bug142.
:- interface.
:- type r(T)
---> ok(T)
; err.
:- type dcg(T, State) == (pred(r(T), State, State)).
:- mode dcg == in(pred(out, in, out) is det).
:- typeclass dcg(Token, State) <= ((State -> (Token))) where [
].
:- pred or(dcg(T, State)::dcg, dcg(T, State)::dcg,
r(T)::out, State::in, State::out) is det <= dcg(Token, State).
:- pred orr(dcg(T, State)::dcg, dcg(T, State)::dcg, dcg(T, State)::dcg,
r(T)::out, State::in, State::out) is det <= dcg(Token, State).
%------------------------------------------------------------------------------%
%------------------------------------------------------------------------------%
:- implementation.
or(PA, PB, Result, S0, S) :-
PA(RA, S0, S1),
(
RA = ok(V),
S = S1,
Result = ok(V)
;
RA = err,
PB(RB, S0, S),
(
RB = ok(V),
Result = ok(V)
;
RB = err,
Result = err
)
).
orr(PA, PB, PC, Result, S0, S) :-
or(or(PA, PB), PC, Result, S0, S).
%------------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et