[m-rev.] for review: use term representation type in oracle knowledge base.

Ian MacLarty maclarty at cs.mu.OZ.AU
Fri Jan 7 15:19:01 AEDT 2005


For review by anyone.

Estimated hours taken: 4
Branches: main

Change the way atoms in the annotated trace are compared by constructing
a representation of the atom and then doing deterministic comparisons 
on the representation, instead of calling compare_representation on 
the actual atoms, which is cc_multi.

This will make looking up atoms in the knowledge base deterministic instead
of cc_multi, which is considerably easier to program with.

browser/declarative_debugger.m
	Define an exception as a term representation instead of a univ.
	
browser/declarative_execution.m
	In the annotated trace store atom arguments and exceptions as 
	term_reps instead of univs.

	Make predicates that construct an atom argument and an exception
	cc_multi.
	
browser/declarative_oracle.m
	Remove the dependency on tree234_cc and set_cc - use map and set
	instead.

	Also make predicates that look up info in the knowledge base semidet
	instead of cc_multi.

browser/declarative_user.m
	Convert term_reps back to univs before printing them.

browser/term_rep.m
	New module implementing the term_rep type.

trace/mercury_trace_declarative.c
	Use new versions of procs to construct exceptions and atom
	arguments.

Index: browser/declarative_debugger.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/declarative_debugger.m,v
retrieving revision 1.44
diff -u -r1.44 declarative_debugger.m
--- browser/declarative_debugger.m	6 Jan 2005 03:20:08 -0000	1.44
+++ browser/declarative_debugger.m	7 Jan 2005 02:01:46 -0000
@@ -62,6 +62,8 @@
 :- import_module mdbcomp__program_representation.
 :- import_module mdb.browser_info.
 
+:- import_module term_rep.
+
 :- import_module io, list, std_util, string.
 
 	% This type represents the possible truth values for nodes
@@ -212,7 +214,7 @@
 			final_io_actions	:: list(io_action)
 		).
 
-:- type decl_exception == univ.
+:- type decl_exception == term_rep.
 
 	% The diagnoser eventually responds with a value of this type
 	% after it is called.
Index: browser/declarative_execution.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/declarative_execution.m,v
retrieving revision 1.29
diff -u -r1.29 declarative_execution.m
--- browser/declarative_execution.m	16 Dec 2004 00:12:38 -0000	1.29
+++ browser/declarative_execution.m	6 Jan 2005 14:18:29 -0000
@@ -21,7 +21,7 @@
 :- import_module mdb__util.
 :- import_module mdbcomp__program_representation.
 
-:- import_module list, std_util, io, bool.
+:- import_module list, std_util, io, bool, term_rep.
 
 	% This type represents a port in the annotated trace.
 	% The type R is the type of references to other nodes
@@ -95,7 +95,7 @@
 						% Call event.
 			excp_redo		:: R,
 						% Previous redo, if any.
-			excp_value		:: univ,
+			excp_value		:: term_rep,
 						% Exception thrown.
 			excp_event		:: event_number
 						% Trace event number.
@@ -171,7 +171,7 @@
 						% programmer visible headvar
 						% (as opposed to a variable
 						% created by the compiler).
-			arg_value		:: maybe(univ)
+			arg_value		:: maybe(term_rep)
 		).
 
 :- type trace_atom
@@ -1125,13 +1125,15 @@
 construct_fail_node(Preceding, Call, Redo, EventNo) =
 		fail(Preceding, Call, Redo, EventNo).
 
-:- func construct_excp_node(trace_node_id, trace_node_id, trace_node_id,
-		univ, event_number) = trace_node(trace_node_id).
-:- pragma export(construct_excp_node(in, in, in, in, in) = out,
+:- pred construct_excp_node(trace_node_id::in, trace_node_id::in, 
+	trace_node_id::in, univ::in, event_number::in, 
+	trace_node(trace_node_id)::out) is cc_multi.
+:- pragma export(construct_excp_node(in, in, in, in, in, out),
 		"MR_DD_construct_excp_node").
 
-construct_excp_node(Preceding, Call, MaybeRedo, Exception, EventNo) =
-		excp(Preceding, Call, MaybeRedo, Exception, EventNo).
+construct_excp_node(Preceding, Call, MaybeRedo, Exception, EventNo, Excp) :-
+		term_rep.univ_to_rep(Exception, ExceptionRep),
+		Excp = excp(Preceding, Call, MaybeRedo, ExceptionRep, EventNo).
 
 :- func construct_switch_node(trace_node_id, goal_path_string)
 		= trace_node(trace_node_id).
@@ -1225,18 +1227,20 @@
 construct_trace_atom(ProcLabel, Arity) = atom(ProcLabel, Args) :-
 	list__duplicate(Arity, dummy_arg_info, Args).
 
-	% add_trace_atom_arg_value(Atom0, ArgNum, HldsNum, ProgVis, Val):
+	% add_trace_atom_arg_value(ArgNum, HldsNum, ProgVis, Val, !Atom):
 	% Register the fact that argument number ArgNum in Atom is the HLDS
 	% variable whose number is HldsNum and whose value is Val. ProgVis
 	% is a C boolean, which is true iff variable HldsNum is a user visible
 	% variable.
-:- func add_trace_atom_arg_value(trace_atom, int, int, int, univ) = trace_atom.
-:- pragma export(add_trace_atom_arg_value(in, in, in, in, in) = out,
+:- pred add_trace_atom_arg_value(int::in, int::in, int::in, univ::in, 
+	trace_atom::in, trace_atom::out) is cc_multi.
+:- pragma export(add_trace_atom_arg_value(in, in, in, in, in, out),
 		"MR_DD_add_trace_atom_arg_value").
 
-add_trace_atom_arg_value(atom(P, Args0), ArgNum, HldsNum, ProgVis, Val)
-		= atom(P, Args) :-
-	Arg = arg_info(c_bool_to_merc_bool(ProgVis), HldsNum, yes(Val)),
+add_trace_atom_arg_value(ArgNum, HldsNum, ProgVis, Val, atom(P, Args0),
+		atom(P, Args)) :-
+	term_rep.univ_to_rep(Val, Rep),
+	Arg = arg_info(c_bool_to_merc_bool(ProgVis), HldsNum, yes(Rep)),
 	list__replace_nth_det(Args0, ArgNum, Arg, Args).
 
 	% Like add_trace_atom_arg_value, except that the specified variable
Index: browser/declarative_oracle.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/declarative_oracle.m,v
retrieving revision 1.31
diff -u -r1.31 declarative_oracle.m
--- browser/declarative_oracle.m	5 Jan 2005 12:25:54 -0000	1.31
+++ browser/declarative_oracle.m	7 Jan 2005 01:59:26 -0000
@@ -103,7 +103,7 @@
 	% will get an answer to the question from the user.
 	%
 :- pred revise_oracle(decl_question(T)::in, oracle_state::in, oracle_state::out)
-	is cc_multi.
+	is det.
 
 	% Returns the state of the term browser.
 	%
@@ -120,8 +120,6 @@
 :- implementation.
 
 :- import_module mdb__declarative_user.
-:- import_module mdb__tree234_cc.
-:- import_module mdb__set_cc.
 :- import_module mdb__util.
 
 :- import_module map, bool, std_util, set, int, bimap, counter, assoc_list,
@@ -129,9 +127,8 @@
 :- import_module library.
 
 query_oracle(Question, Response, !Oracle, !IO) :-
-	answer_known(!.Oracle, Question, MaybeAnswer),
 	(
-		MaybeAnswer = yes(Answer)
+		answer_known(!.Oracle, Question, Answer)
 	->
 		Response = oracle_answer(Answer)
 	;
@@ -141,12 +138,12 @@
 	).
 
 :- pred make_user_question(oracle_kb::in, decl_question(T)::in,
-	user_question(T)::out) is cc_multi.
+	user_question(T)::out) is det.
 
 make_user_question(Revised, DeclQuestion, UserQuestion) :-
-	query_oracle_kb(Revised, DeclQuestion, MaybeDeclAnswer),
 	(
-		MaybeDeclAnswer = yes(truth_value(_, DeclTruth))
+		query_oracle_kb(Revised, DeclQuestion, Answer),
+		Answer = truth_value(_, DeclTruth)
 	->
 		UserQuestion = question_with_default(DeclQuestion, DeclTruth)
 	;
@@ -207,9 +204,8 @@
 
 revise_oracle(Question, !Oracle) :-
 	Current0 = !.Oracle ^ kb_current,
-	query_oracle_kb(Current0, Question, MaybeAnswer),
 	(
-		MaybeAnswer = yes(Answer)
+		query_oracle_kb(Current0, Question, Answer)
 	->
 		retract_oracle_kb(Question, Current0, Current),
 		Revised0 = !.Oracle ^ kb_revised,
@@ -394,7 +390,7 @@
 		% case that the user supplies a truth value for a
 		% "wrong answer" node.
 		%
-		kb_ground_map :: map_cc(final_decl_atom, decl_truth),
+		kb_ground_map :: map(final_decl_atom, decl_truth),
 
 		% This map stores knowledge about the completeness of the
 		% set of solutions generated by calling the given initial
@@ -402,65 +398,63 @@
 		% the user supplies a truth value for a "missing answer"
 		% node.
 		%
-		kb_complete_map :: map_cc(init_decl_atom, decl_truth),
+		kb_complete_map :: map(init_decl_atom, decl_truth),
 
 		% Mapping from call atoms to information about which
 		% exceptions are possible or impossible.
 		%
-		kb_exceptions_map :: map_cc(init_decl_atom, known_exceptions)
+		kb_exceptions_map :: map(init_decl_atom, known_exceptions)
 	).
 
-:- type map_cc(K, V) == tree234_cc(K, V).
-
 :- type known_exceptions
 	--->	known_excp(
 				% Possible exceptions
-			possible	:: set_cc(decl_exception),
+			possible	:: set(decl_exception),
 				% Impossible exceptions
-			impossible	:: set_cc(decl_exception),
+			impossible	:: set(decl_exception),
 				% Exceptions from inadmissible calls
-			inadmissible	:: set_cc(decl_exception)
+			inadmissible	:: set(decl_exception)
 		).
 
 :- pred oracle_kb_init(oracle_kb).
 :- mode oracle_kb_init(out) is det.
 
 oracle_kb_init(oracle_kb(G, C, X)) :-
-	tree234_cc__init(G),
-	tree234_cc__init(C),
-	tree234_cc__init(X).
+	map.init(G),
+	map.init(C),
+	map.init(X).
 
-:- pred get_kb_ground_map(oracle_kb, map_cc(final_decl_atom, decl_truth)).
+:- pred get_kb_ground_map(oracle_kb, map(final_decl_atom, decl_truth)).
 :- mode get_kb_ground_map(in, out) is det.
 
 get_kb_ground_map(KB, KB ^ kb_ground_map).
 
-:- pred set_kb_ground_map(oracle_kb, map_cc(final_decl_atom, decl_truth),
+:- pred set_kb_ground_map(oracle_kb, map(final_decl_atom, decl_truth),
 	oracle_kb).
 :- mode set_kb_ground_map(in, in, out) is det.
 
 set_kb_ground_map(KB, M, KB ^ kb_ground_map := M).
 
 :- pred get_kb_complete_map(oracle_kb,
-	map_cc(init_decl_atom, decl_truth)).
+	map(init_decl_atom, decl_truth)).
 :- mode get_kb_complete_map(in, out) is det.
 
 get_kb_complete_map(KB, KB ^ kb_complete_map).
 
 :- pred set_kb_complete_map(oracle_kb,
-	map_cc(init_decl_atom, decl_truth), oracle_kb).
+	map(init_decl_atom, decl_truth), oracle_kb).
 :- mode set_kb_complete_map(in, in, out) is det.
 
 set_kb_complete_map(KB, M, KB ^ kb_complete_map := M).
 
 :- pred get_kb_exceptions_map(oracle_kb,
-	map_cc(init_decl_atom, known_exceptions)).
+	map(init_decl_atom, known_exceptions)).
 :- mode get_kb_exceptions_map(in, out) is det.
 
 get_kb_exceptions_map(KB, KB ^ kb_exceptions_map).
 
 :- pred set_kb_exceptions_map(oracle_kb,
-	map_cc(init_decl_atom, known_exceptions), oracle_kb).
+	map(init_decl_atom, known_exceptions), oracle_kb).
 :- mode set_kb_exceptions_map(in, in, out) is det.
 
 set_kb_exceptions_map(KB, M, KB ^ kb_exceptions_map := M).
@@ -468,9 +462,9 @@
 %-----------------------------------------------------------------------------%
 
 :- pred answer_known(oracle_state::in, decl_question(T)::in,
-	maybe(decl_answer(T))::out) is cc_multi.
+	decl_answer(T)::out) is semidet.
 
-answer_known(Oracle, Question, MaybeAnswer) :-
+answer_known(Oracle, Question, Answer) :-
 	Atom = get_decl_question_atom(Question),
 	(
 		trusted(Atom ^ proc_layout, Oracle)
@@ -479,9 +473,9 @@
 		% however it's children may still contain bugs, since 
 		% trusted procs may call untrusted procs (for example
 		% when an untrusted closure is passed to a trusted predicate).
-		MaybeAnswer = yes(ignore(get_decl_question_node(Question)))
+		Answer = ignore(get_decl_question_node(Question))
 	;
-		query_oracle_kb(Oracle ^ kb_current, Question, MaybeAnswer)
+		query_oracle_kb(Oracle ^ kb_current, Question, Answer)
 	).	
 
 :- pred trusted(proc_layout::in, oracle_state::in) is semidet.
@@ -509,64 +503,37 @@
 	).
 
 :- pred query_oracle_kb(oracle_kb::in, decl_question(T)::in,
-	maybe(decl_answer(T))::out) is cc_multi.
+	decl_answer(T)::out) is semidet.
 
-query_oracle_kb(KB, Question, Result) :-
+query_oracle_kb(KB, Question, Answer) :-
 	Question = wrong_answer(Node, Atom),
 	get_kb_ground_map(KB, Map),
-	tree234_cc__search(Map, Atom, MaybeTruth),
-	(
-		MaybeTruth = yes(Truth),
-		Result = yes(truth_value(Node, Truth))
-	;
-		MaybeTruth = no,
-		Result = no
-	).
+	map.search(Map, Atom, Truth),
+	Answer = truth_value(Node, Truth).
 
-query_oracle_kb(KB, Question, Result) :-
+query_oracle_kb(KB, Question, Answer) :-
 	Question = missing_answer(Node, Call, _Solns),
 	get_kb_complete_map(KB, CMap),
-	tree234_cc__search(CMap, Call, MaybeTruth),
-	(
-		MaybeTruth = yes(Truth),
-		Result = yes(truth_value(Node, Truth))
-	;
-		MaybeTruth = no,
-		Result = no
-	).
+	map.search(CMap, Call, Truth),
+	Answer = truth_value(Node, Truth).
 
-query_oracle_kb(KB, Question, Result) :-
+query_oracle_kb(KB, Question, Answer) :-
 	Question = unexpected_exception(Node, Call, Exception),
 	get_kb_exceptions_map(KB, XMap),
-	tree234_cc__search(XMap, Call, MaybeX),
+	map.search(XMap, Call, X),
+	X = known_excp(Possible, Impossible, Inadmissible),
 	(
-		MaybeX = no,
-		Result = no
+		set.member(Exception, Possible)
+	->
+		Answer = truth_value(Node, correct)
 	;
-		MaybeX = yes(known_excp(Possible, Impossible, Inadmissible)),
-		member(Exception, Possible, PossibleBool),
 		(
-			PossibleBool = yes,
-			Result = yes(truth_value(Node, correct))
+			set.member(Exception, Impossible)
+		->
+			Answer = truth_value(Node, erroneous)
 		;
-			PossibleBool = no,
-			member(Exception, Impossible, ImpossibleBool),
-			(
-				ImpossibleBool = yes,
-				Result = yes(truth_value(Node, erroneous))
-			;
-				ImpossibleBool = no,
-				member(Exception, Inadmissible,
-					InadmissibleBool),
-				(
-					InadmissibleBool = yes,
-					Result = yes(truth_value(Node, 
-						inadmissible))
-				;	
-					InadmissibleBool = no,
-					Result = no
-				)
-			)
+			member(Exception, Inadmissible),
+			Answer = truth_value(Node, inadmissible)
 		)
 	).
 
@@ -577,7 +544,7 @@
 	%
 :- pred assert_oracle_kb(decl_question(T), decl_answer(T), oracle_kb,
 		oracle_kb).
-:- mode assert_oracle_kb(in, in, in, out) is cc_multi.
+:- mode assert_oracle_kb(in, in, in, out) is det.
 
 assert_oracle_kb(_, suspicious_subterm(_, _, _), KB, KB).
 
@@ -607,20 +574,20 @@
 
 assert_oracle_kb(missing_answer(_, Call, _), truth_value(_, Truth), KB0, KB) :-
 	get_kb_complete_map(KB0, Map0),
-	tree234_cc__set(Map0, Call, Truth, Map),
+	map.set(Map0, Call, Truth, Map),
 	set_kb_complete_map(KB0, Map, KB).
 
 assert_oracle_kb(unexpected_exception(_, Call, Exception),
 		truth_value(_, Truth), KB0, KB) :-
 	get_kb_exceptions_map(KB0, Map0),
-	tree234_cc__search(Map0, Call, MaybeX),
 	(
-		MaybeX = yes(KnownExceptions0)
+		map.search(Map0, Call, Found)
+	->
+		KnownExceptions0 = Found
 	;
-		MaybeX = no,
-		set_cc.init(Possible0),
-		set_cc.init(Impossible0),
-		set_cc.init(Inadmissible0),
+		set.init(Possible0),
+		set.init(Impossible0),
+		set.init(Inadmissible0),
 		KnownExceptions0 = known_excp(Possible0, Impossible0,
 			Inadmissible0)
 	),
@@ -641,11 +608,11 @@
 		KnownExceptions = KnownExceptions0 ^ inadmissible := 	
 			Inadmissible
 	),
-	tree234_cc__set(Map0, Call, KnownExceptions, Map),
+	map.set(Map0, Call, KnownExceptions, Map),
 	set_kb_exceptions_map(KB0, Map, KB).
 
 :- pred retract_oracle_kb(decl_question(T), oracle_kb, oracle_kb).
-:- mode retract_oracle_kb(in, in, out) is cc_multi.
+:- mode retract_oracle_kb(in, in, out) is det.
 
 retract_oracle_kb(wrong_answer(_, Atom), KB0, KB) :-
 	Map0 = KB0 ^ kb_ground_map,
@@ -657,22 +624,22 @@
 
 retract_oracle_kb(missing_answer(_, InitAtom, _), KB0, KB) :-
 	CompleteMap0 = KB0 ^ kb_complete_map,
-	tree234_cc__delete(CompleteMap0, InitAtom, CompleteMap),
+	map.delete(CompleteMap0, InitAtom, CompleteMap),
 	KB = KB0 ^ kb_complete_map := CompleteMap.
 
 retract_oracle_kb(unexpected_exception(_, InitAtom, Exception), KB0, KB) :-
 	ExceptionsMap0 = KB0 ^ kb_exceptions_map,
-	tree234_cc__search(ExceptionsMap0, InitAtom, MaybeKnownExceptions0),
 	(
-		MaybeKnownExceptions0 = yes(known_excp(Possible0, Impossible0,
-			Inadmissible0))
+		map.search(ExceptionsMap0, InitAtom, KnownExceptions0),
+		KnownExceptions0 = known_excp(Possible0, Impossible0,
+			Inadmissible0)
 	->
-		set_cc__delete(Possible0, Exception, Possible),
-		set_cc__delete(Impossible0, Exception, Impossible),
-		set_cc__delete(Inadmissible0, Exception, Inadmissible),
+		set.delete(Possible0, Exception, Possible),
+		set.delete(Impossible0, Exception, Impossible),
+		set.delete(Inadmissible0, Exception, Inadmissible),
 		KnownExceptions = known_excp(Possible, Impossible,
 			Inadmissible),
-		tree234_cc__set(ExceptionsMap0, InitAtom, KnownExceptions,
+		map.set(ExceptionsMap0, InitAtom, KnownExceptions,
 			ExceptionsMap)
 	;
 		ExceptionsMap = ExceptionsMap0
@@ -680,20 +647,20 @@
 	KB = KB0 ^ kb_exceptions_map := ExceptionsMap.
 
 :- pred add_atom_to_ground_map(decl_truth::in, final_decl_atom::in, 
-	proc_layout::in, map_cc(final_decl_atom, decl_truth)::in,
-	map_cc(final_decl_atom, decl_truth)::out) is cc_multi.
+	proc_layout::in, map(final_decl_atom, decl_truth)::in,
+	map(final_decl_atom, decl_truth)::out) is det.
 
 add_atom_to_ground_map(Truth, FinalAtom, ProcLayout, Map0, Map) :-
-	tree234_cc.set(Map0, final_decl_atom(
+	map.set(Map0, final_decl_atom(
 		atom(ProcLayout, FinalAtom ^ final_atom ^ atom_args),
 		FinalAtom ^ final_io_actions), Truth, Map).
 
 :- pred remove_atom_from_ground_map(final_decl_atom::in, 
-	proc_layout::in, map_cc(final_decl_atom, decl_truth)::in,
-	map_cc(final_decl_atom, decl_truth)::out) is cc_multi.
+	proc_layout::in, map(final_decl_atom, decl_truth)::in,
+	map(final_decl_atom, decl_truth)::out) is det.
 
 remove_atom_from_ground_map(FinalAtom, ProcLayout, Map0, Map) :-
-	tree234_cc.delete(Map0, final_decl_atom(
+	map.delete(Map0, final_decl_atom(
 		atom(ProcLayout, FinalAtom ^ final_atom ^ atom_args),
 		FinalAtom ^ final_io_actions), Map).
 
Index: browser/declarative_user.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/declarative_user.m,v
retrieving revision 1.34
diff -u -r1.34 declarative_user.m
--- browser/declarative_user.m	6 Jan 2005 03:20:09 -0000	1.34
+++ browser/declarative_user.m	7 Jan 2005 02:06:16 -0000
@@ -73,6 +73,8 @@
 :- import_module mdbcomp__program_representation.
 :- import_module mdb.parse.
 
+:- import_module term_rep.
+
 :- import_module std_util, char, string, bool, int, deconstruct, getopt, list.
 
 :- type user_state
@@ -390,7 +392,8 @@
 	(
 		list__index1(Args, ArgNum, ArgInfo),
 		ArgInfo = arg_info(_, _, MaybeArg),
-		MaybeArg = yes(Arg)
+		MaybeArg = yes(ArgRep),
+		term_rep.rep_to_univ(ArgRep, Arg)
 	->
 		browse_browser_term(univ_to_browser_term(Arg),
 			!.User ^ instr, !.User ^ outstr,
@@ -429,7 +432,8 @@
 		UserVisible = yes
 	->
 		(
-			MaybeValue = yes(Value)
+			MaybeValue = yes(ValueRep),
+			term_rep.rep_to_univ(ValueRep, Value)
 		;
 			MaybeValue = no,
 			Value = univ('_'`with_type`unbound)
@@ -462,7 +466,8 @@
 	(
 		list__index1(Args, ArgNum, ArgInfo),
 		ArgInfo = arg_info(_, _, MaybeArg),
-		MaybeArg = yes(Arg)
+		MaybeArg = yes(ArgRep),
+		term_rep.rep_to_univ(ArgRep, Arg)
 	->
 		print_browser_term(univ_to_browser_term(Arg), User ^ outstr,
 			decl_caller_type, User ^ browser, !IO),
@@ -739,9 +744,10 @@
 		list__foldl(write_decl_final_atom(User, "\t", print_all), Solns)
 	).
 
-write_decl_question(unexpected_exception(_, Call, Exception), User) -->
+write_decl_question(unexpected_exception(_, Call, ExceptionRep), User) -->
 	write_decl_init_atom(User, "Call ", decl_caller_type, Call),
 	io__write_string(User ^ outstr, "Throws "),
+	{ term_rep.rep_to_univ(ExceptionRep, Exception) },
 	io__write(User ^ outstr, include_details_cc, univ_value(Exception)),
 	io__nl(User ^ outstr).
 
@@ -761,9 +767,10 @@
 				"Found partially uncovered atom:\n"),
 		write_decl_init_atom(User, "", decl_caller_type, Atom)
 	;
-		{ EBug = unhandled_exception(Atom, Exception, _) },
+		{ EBug = unhandled_exception(Atom, ExceptionRep, _) },
 		io__write_string(User ^ outstr, "Found unhandled exception:\n"),
 		write_decl_init_atom(User, "", decl_caller_type, Atom),
+		{ term_rep.rep_to_univ(ExceptionRep, Exception) },
 		io__write(User ^ outstr, include_details_cc,
 				univ_value(Exception)),
 		io__nl(User ^ outstr)
@@ -815,7 +822,8 @@
 trace_atom_arg_to_univ(TraceAtomArg, Univ) :-
 	MaybeUniv = TraceAtomArg ^ arg_value,
 	(
-		MaybeUniv = yes(Univ)
+		MaybeUniv = yes(Rep),
+		term_rep.rep_to_univ(Rep, Univ)
 	;
 		MaybeUniv = no,
 		Univ = univ('_' `with_type` unbound)
Index: browser/term_rep.m
===================================================================
RCS file: browser/term_rep.m
diff -N browser/term_rep.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ browser/term_rep.m	7 Jan 2005 02:14:06 -0000
@@ -0,0 +1,62 @@
+%-----------------------------------------------------------------------------%
+% Copyright (C) 1999-2005 The University of Melbourne.
+% This file may only be copied under the terms of the GNU Library General
+% Public License - see the file COPYING.LIB in the Mercury distribution.
+%-----------------------------------------------------------------------------%
+% File: term_rep.m
+% Author: Ian MacLarty
+%
+% This module implements an abstract type, term_rep, values of which are the
+% representation of some other value.  Constructing a representation from a
+% term is cc_multi, but then doing comparisons on the representation is
+% deterministic.
+%
+% This is useful when we only want to consider the representation of a term
+% and don't care about it's actual value.
+%
+
+:- module term_rep.
+
+:- interface.
+
+:- import_module std_util.
+
+:- type term_rep.
+
+:- pred univ_to_rep(univ::in, term_rep::out) is cc_multi.
+
+:- pred rep_to_univ(term_rep::in, univ::out) is det.
+
+%-----------------------------------------------------------------------------%
+
+:- implementation.
+
+:- type term_rep 
+	---> term_rep(univ) 
+	where 
+		equality is term_rep_equal, 
+		comparison is term_rep_compare.
+
+:- pred term_rep_equal(term_rep::in, term_rep::in) is semidet.
+
+term_rep_equal(Rep1, Rep2) :-
+	(=) = promise_only_solution(comp_rep_2(Rep1, Rep2)).
+
+:- pred comp_rep_2(term_rep::in, term_rep::in, builtin.comparison_result::uo)
+	is cc_multi.
+
+comp_rep_2(Rep1, Rep2, Result) :-
+	builtin.compare_representation(Result, Rep1, Rep2).
+
+:- pred term_rep_compare(builtin.comparison_result::uo, term_rep::in,
+	term_rep::in) is det.
+
+term_rep_compare(Result, Rep1, Rep2) :-
+	Result = promise_only_solution(comp_rep_2(Rep1, Rep2)).
+
+univ_to_rep(Univ0, term_rep(Univ)) :- cc_multi_equal(Univ0, Univ).
+
+rep_to_univ(Rep, Univ) :-
+	Univ = promise_only_solution(
+		pred(U::out) is cc_multi :- Rep = term_rep(U)
+	).
Index: trace/mercury_trace_declarative.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_declarative.c,v
retrieving revision 1.75
diff -u -r1.75 mercury_trace_declarative.c
--- trace/mercury_trace_declarative.c	16 Dec 2004 00:12:41 -0000	1.75
+++ trace/mercury_trace_declarative.c	6 Jan 2005 14:20:09 -0000
@@ -732,10 +732,10 @@
 	MR_TRACE_CALL_MERCURY(
 		last_interface = MR_DD_call_node_get_last_interface(
 				(MR_Word) call);
-		node = (MR_Trace_Node) MR_DD_construct_excp_node(
+		MR_DD_construct_excp_node(
 				(MR_Word) prev, (MR_Word) call, last_interface,
 				MR_trace_get_exception_value(),
-				(MR_Word) event_info->MR_event_number);
+				(MR_Word) event_info->MR_event_number, &node);
 		MR_DD_call_node_set_last_interface(
 				(MR_Word) call, (MR_Word) node);
 	);
@@ -1142,9 +1142,10 @@
 			);
 
 			MR_TRACE_CALL_MERCURY(
-				atom = MR_DD_add_trace_atom_arg_value(atom,
+				MR_DD_add_trace_atom_arg_value(
 					(MR_Word) hv + 1, hlds_num,
-					is_prog_visible_headvar, arg);
+					is_prog_visible_headvar, arg, atom,
+					&atom);
 			);
 		}
 	}
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list