Files
mercury/tests/debugger/ambiguity_helper.m
Zoltan Somogyi e35a09542e Print two kinds of ambiguities only if asked for.
trace/mercury_trace_cmd_developer.c:
trace/mercury_trace_tables.[ch]:
    Add two options to the mdb command "ambiguity".

    Print ambiguities between function and predicate forms of the same
    operation, such as list.length, only if the new option -b, or
    --both-pred-and-func, is given.

    Print ambiguities involving procedures that were created by type
    specialization only if the new option -s, or --typespec is given.
    (The -t option name was already taken.)

    These changes remove from the ambiguity command's output
    (some of) the parts that are not useful when one wants to eliminate
    ambiguities by renaming.

    Clarify a heading.

doc/user_guide.texi:
    Document the above changes.

runtime/mercury_proc_id.h:
    Fix a field name that has become misleading.

    MR_UserProcId_Structs have a field named MR_user_arity.
    In this name, the "MR_user_" part is a prefix shared by the other
    fields in that structure, to indicate that they are part of the id
    of a user-defined procedure, as opposed to a compiler-created
    unify, compare or index procedure. However, the arity it contains
    is what the compiler now calls a pred_form_arity: it does not count
    type_info and typeclass_info arguments added by polymorphism, but
    it *does* count function return values for functions. This is now
    misleading, because in the compiler, a user_arity does *not* count
    function return values for functions.

    Replace this field name with MR_user_pred_form_arity, which tells
    readers that this arity is a pred_form_arity. The presence of the
    "user" part of the name may still cause some confusion, but at least
    that confusion should motivate readers to look up the field name,
    whose comment should clarify things.

mdbcomp/rtti_access.m:
runtime/mercury_debug.c:
runtime/mercury_deep_profiling.c:
runtime/mercury_ho_call.c:
runtime/mercury_layout_util.c:
runtime/mercury_ml_expand_body.h:
runtime/mercury_stack_layout.h:
runtime/mercury_trace_base.c:
trace/mercury_trace.c:
trace/mercury_trace_external.c:
trace/mercury_trace_util.c:
    Conform to the change in mercury_proc_id.h.

tests/debugger/ambiguity.{m,inp,exp}:
tests/debugger/ambiguity_helper.m:
    Expand this test case to test the new functionality.
    The type specialized predicates are in a new helper module,
    because this is the simplest way to avoid dead procedure elimination
    deleting any of the predicates whose names we want to test for ambiguities.
2022-07-05 08:00:12 +10:00

93 lines
2.4 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
:- module ambiguity_helper.
:- interface.
:- import_module list.
:- pred zero_int(int::out) is det.
:- pred add_int(int::in, int::in, int::out) is det.
:- func add_int(int, int) = int.
:- pred zero_float(float::out) is det.
:- pred add_float(float::in, float::in, float::out) is det.
:- func add_float(float, float) = float.
:- typeclass summable(T) where [
(pred zero(T::out) is det),
(pred sum(T::in, T::in, T::out) is det)
].
:- instance summable(int).
:- instance summable(float).
:- pred get_length_sum(list(T)::in, T::out, int::out) is det
<= summable(T).
:- pragma type_spec(pred(ambiguity_helper.get_length_sum/3), T = int).
:- pragma type_spec(pred(ambiguity_helper.get_length_sum/3), T = float).
:- pred get_length_sum_via_acc(list(T)::in, T::out, int::out) is det
<= summable(T).
:- pragma type_spec(pred(ambiguity_helper.get_length_sum_via_acc/3), T = int).
:- pragma type_spec(pred(ambiguity_helper.get_length_sum_via_acc/3), T = float).
%---------------------------------------------------------------------------%
:- implementation.
:- import_module float.
:- import_module int.
:- instance summable(int) where [
pred(zero/1) is zero_int,
pred(sum/3) is add_int
].
:- instance summable(float) where [
pred(zero/1) is zero_float,
pred(sum/3) is add_float
].
%---------------------%
zero_int(0).
add_int(A, B, A + B).
add_int(A, B) = A + B.
%---------------------%
zero_float(0.0).
add_float(A, B, A + B).
add_float(A, B) = A + B.
%---------------------%
get_length_sum([], Sum, 0) :-
zero(Sum).
get_length_sum([Head | Tail], Sum, Len) :-
get_length_sum(Tail, TailSum, TailLen),
sum(Head, TailSum, Sum),
Len = 1 + TailLen.
get_length_sum_via_acc(List, Sum, Len) :-
zero(Sum0),
get_length_sum(List, Sum0, Sum, 0, Len).
:- pred get_length_sum(list(T)::in, T::in, T::out, int::in, int::out) is det
<= summable(T).
:- pragma type_spec(pred(ambiguity_helper.get_length_sum/5), T = int).
:- pragma type_spec(pred(ambiguity_helper.get_length_sum/5), T = float).
get_length_sum([], !Sum, !Len).
get_length_sum([Head | Tail], !Sum, !Len) :-
get_length_sum(Tail, !Sum, !Len),
sum(Head, !.Sum, !:Sum),
!:Len = 1 + !.Len.