mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-25 14:24:11 +00:00
Estimated hours taken: 6
Branches: main
Fix two bugs in the printing of goals where the predicate concerned is an
compiler-generated unify, compare or index predicate. Improve the mechanisms
for debugging bugs like this.
runtime/mercury_layout_util.[ch]:
Fix bug one: do not return the arity of a type constructor as
the arity of the unify, compare or index predicate of that
type constructor; return the actual arity. When the falsely
returned arity was greater than the actual arity, we could get
core dumps; when it was smaller, the mdb command "print goal"
printed wrong output.
Provide a mechanism for fixing bug two: add a utility function
for computing *correctly* a procedure's original arity and the number
of type_info and/or typeclass_info arguments added by the compiler.
(For convenience, it also returns a predicate/function indication.)
runtime/mercury_stack_layout.h:
Rename the MR_comp_arity field of MR_Compiler_Proc_Id to
MR_comp_type_arity, to make clear that it gives the arity of the type
constructor, not the arity of the predicate, and thus avoid bugs such
as those above.
runtime/mercury_stack_trace.c:
Use the new name of the MR_comp_type_arity field.
trace/mercury_trace_declarative.c:
trace/mercury_trace_vars.c:
Call the new, correct utility function in runtime/mercury_layout_util
to compute how many typeinfo and/or typeclassinfo arguments are added
by the compiler to a unify, compare, or index procedure's arguments,
instead of the different, but logically equivalent and equally wrong
pieces of code here.
trace/mercury_trace_external.c:
Use the new name of the MR_comp_type_arity field. Leave an XXX, since
I am not sure whether Morphine interprets the arity as the arity of the
type constructor or as the arity of the predicate.
runtime/mercury_engine.[ch]:
runtime/mercury_layout_util.c:
Make the printing of locations obtained from RTTI data structures
switchable from mdb, to make problems like this easier to debug.
tests/debugger/uci.{m,inp,exp}:
A new test case to test the proper handling of unify, compare and index
predicates.
tests/debugger/Mercury.options:
tests/debugger/Mmakefile:
Enable the new test case.
123 lines
2.4 KiB
Mathematica
123 lines
2.4 KiB
Mathematica
% This test case checks the debugger's handling of unify, compare and index
|
|
% predicates. Versions of the runtime system before 29 Mar 2003 used to have
|
|
% a bug in computing their arities.
|
|
|
|
:- module uci.
|
|
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module string, list.
|
|
|
|
main(!IO) :-
|
|
test([], RevResults),
|
|
list__reverse(RevResults, Results),
|
|
string__append_list(Results, ResultString),
|
|
io__write_string(ResultString, !IO).
|
|
|
|
:- pred test(list(string)::in, list(string)::out) is det.
|
|
|
|
test(!Res) :-
|
|
( compare((<), ma0, mb0) ->
|
|
add_res("0 lt\n", !Res)
|
|
;
|
|
add_res("0 ge\n", !Res)
|
|
),
|
|
( compare((<), mb1, ma1) ->
|
|
add_res("1 lt\n", !Res)
|
|
;
|
|
add_res("1 ge\n", !Res)
|
|
),
|
|
( compare((<), ma2, ma2) ->
|
|
add_res("2 lt\n", !Res)
|
|
;
|
|
add_res("2 ge\n", !Res)
|
|
),
|
|
( compare((<), mb3, ma3) ->
|
|
add_res("3 lt\n", !Res)
|
|
;
|
|
add_res("3 ge\n", !Res)
|
|
),
|
|
( compare((<), ma4, mb4) ->
|
|
add_res("4 lt\n", !Res)
|
|
;
|
|
add_res("4 ge\n", !Res)
|
|
),
|
|
( unify(ma0, mb0) ->
|
|
add_res("0 eq\n", !Res)
|
|
;
|
|
add_res("0 ne\n", !Res)
|
|
),
|
|
( unify(ma1, ma1) ->
|
|
add_res("1 eq\n", !Res)
|
|
;
|
|
add_res("1 ne\n", !Res)
|
|
),
|
|
( unify(ma2, mb2) ->
|
|
add_res("2 eq\n", !Res)
|
|
;
|
|
add_res("2 ne\n", !Res)
|
|
),
|
|
( unify(mb3, mb3) ->
|
|
add_res("3 eq\n", !Res)
|
|
;
|
|
add_res("3 ne\n", !Res)
|
|
),
|
|
( unify(ma4, mb4) ->
|
|
add_res("4 eq\n", !Res)
|
|
;
|
|
add_res("4 ne\n", !Res)
|
|
),
|
|
( compare((<), mai, mbi) ->
|
|
add_res("i lt\n", !Res)
|
|
;
|
|
add_res("i ge\n", !Res)
|
|
).
|
|
|
|
:- pred add_res(string::in, list(string)::in, list(string)::out) is det.
|
|
|
|
add_res(R, Rs0, [R | Rs0]).
|
|
|
|
:- type t0 ---> a0 ; b0.
|
|
:- type t1(A) ---> a1(A) ; b1(A).
|
|
:- type t2(A, B) ---> a2(A, B) ; b2(A, B).
|
|
:- type t3(A, B, C) ---> a3(A, B, C) ; b3(A, B, C).
|
|
:- type t4(A, B, C, D) ---> a4(A, B, C, D) ; b4(A, B, C, D).
|
|
|
|
:- type i(A, B, C) ---> ai(A) ; bi(B) ; ci(C).
|
|
|
|
:- func ma0 = t0.
|
|
:- func mb0 = t0.
|
|
:- func ma1 = t1(int).
|
|
:- func mb1 = t1(int).
|
|
:- func ma2 = t2(int, int).
|
|
:- func mb2 = t2(int, int).
|
|
:- func ma3 = t3(int, int, int).
|
|
:- func mb3 = t3(int, int, int).
|
|
:- func ma4 = t4(int, int, int, int).
|
|
:- func mb4 = t4(int, int, int, int).
|
|
|
|
:- func mai = i(int, int, int).
|
|
:- func mbi = i(int, int, int).
|
|
:- func mci = i(int, int, int).
|
|
|
|
ma0 = a0.
|
|
mb0 = b0.
|
|
ma1 = a1(1).
|
|
mb1 = b1(11).
|
|
ma2 = a2(1, 2).
|
|
mb2 = b2(11, 12).
|
|
ma3 = a3(1, 2, 3).
|
|
mb3 = b3(11, 12, 13).
|
|
ma4 = a4(1, 2, 3, 4).
|
|
mb4 = b4(11, 12, 13, 14).
|
|
|
|
mai = ai(1).
|
|
mbi = bi(11).
|
|
mci = ci(111).
|