[m-rev.] diff: avoid runtime aborts (2)

Mark Brown dougl at cs.mu.OZ.AU
Tue Oct 15 17:38:01 AEST 2002


Hi,

This change fixes the remaining test case for the declarative debugger,
which means that we should now pass all of the declarative debugger
tests.  I'm going to go ahead and commit this now, since it is similar
to an earlier change, and because it will otherwise conflict with
another change that I am about to start working on.  I'll address any
review comments in a subsequent change.

Cheers,
Mark.

Estimated hours taken: 1.5
Branches: main

Implement a committed choice version of the 'set' module, and use this in
the declarative debugging oracle.  This implementation of sets avoids the
use of builtin comparison, which would otherwise cause problems for the
oracle.

This fixes a bug that was causing test case 'ho5' to fail.

browser/set_cc.m:
	The new module.  This is mostly a wrapper around tree234_cc.

browser/mdb.m:
	Make the new module a sub-module of mdb.

browser/declarative_oracle.m:
	Use the new module instead of sets from the standard library.

tests/debugger/declarative/Mmakefile:
tests/debugger/declarative/ho5.exp:
tests/debugger/declarative/ho5.exp2:
tests/debugger/declarative/ho5.inp:
	Enable this test case, and provide input and expected output.

Index: browser/declarative_oracle.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/declarative_oracle.m,v
retrieving revision 1.17
diff -u -r1.17 declarative_oracle.m
--- browser/declarative_oracle.m	10 Oct 2002 19:43:56 -0000	1.17
+++ browser/declarative_oracle.m	10 Oct 2002 19:44:41 -0000
@@ -65,7 +65,7 @@
 %-----------------------------------------------------------------------------%
 
 :- implementation.
-:- import_module mdb__declarative_user, mdb__tree234_cc, mdb__util.
+:- import_module mdb__declarative_user, mdb__tree234_cc, mdb__set_cc, mdb__util.
 :- import_module bool, std_util, set.
 
 query_oracle(Questions, Response, Oracle0, Oracle) -->
@@ -179,8 +179,8 @@
 
 :- type known_exceptions
 	--->	known_excp(
-			set(univ),		% Possible exceptions.
-			set(univ)		% Impossible exceptions.
+			set_cc(univ),		% Possible exceptions.
+			set_cc(univ)		% Impossible exceptions.
 		).
 
 :- pred oracle_kb_init(oracle_kb).
@@ -280,16 +280,20 @@
 		Result = no
 	;
 		MaybeX = yes(known_excp(Possible, Impossible)),
+		set_cc__member(Exception, Possible, PossibleBool),
 		(
-			set__member(Exception, Possible)
-		->
+			PossibleBool = yes,
 			Result = yes(truth_value(Node, yes))
 		;
-			set__member(Exception, Impossible)
-		->
-			Result = yes(truth_value(Node, no))
-		;
-			Result = no
+			PossibleBool = no,
+			set_cc__member(Exception, Impossible, ImpossibleBool),
+			(
+				ImpossibleBool = yes,
+				Result = yes(truth_value(Node, no))
+			;
+				ImpossibleBool = no,
+				Result = no
+			)
 		)
 	).
 
@@ -322,17 +326,17 @@
 		MaybeX = yes(known_excp(Possible0, Impossible0))
 	;
 		MaybeX = no,
-		set__init(Possible0),
-		set__init(Impossible0)
+		set_cc__init(Possible0),
+		set_cc__init(Impossible0)
 	),
 	(
 		Truth = yes,
-		set__insert(Possible0, Exception, Possible),
+		set_cc__insert(Possible0, Exception, Possible),
 		Impossible = Impossible0
 	;
 		Truth = no,
 		Possible = Possible0,
-		set__insert(Impossible0, Exception, Impossible)
+		set_cc__insert(Impossible0, Exception, Impossible)
 	),
 	tree234_cc__set(Map0, Call, known_excp(Possible, Impossible), Map),
 	set_kb_exceptions_map(KB0, Map, KB).
Index: browser/mdb.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/mdb.m,v
retrieving revision 1.9
diff -u -r1.9 mdb.m
--- browser/mdb.m	13 Sep 2002 04:17:40 -0000	1.9
+++ browser/mdb.m	10 Oct 2002 14:48:44 -0000
@@ -23,7 +23,7 @@
 :- include_module frame, parse, util, sized_pretty.
 :- include_module declarative_analyser, declarative_oracle, declarative_tree.
 :- include_module declarative_user.
-:- include_module tree234_cc.
+:- include_module tree234_cc, set_cc.
 
 	% XXX these modules are more generally useful, but the
 	% dynamic linking library is not yet installed anywhere.
Index: browser/set_cc.m
===================================================================
RCS file: browser/set_cc.m
diff -N browser/set_cc.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ browser/set_cc.m	10 Oct 2002 14:48:07 -0000
@@ -0,0 +1,69 @@
+%---------------------------------------------------------------------------%
+% Copyright (C) 2002 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.
+%---------------------------------------------------------------------------%
+
+% Set_cc is an implementation of sets which uses compare_representation
+% instead of builtin comparison, hence it is suitable for use with terms
+% that don't have a canonical representation.  It is implemented using
+% tree234_cc; see that module for further discussion about the implications
+% of using compare_representation.
+%
+% Author: Mark Brown (dougl)
+
+%---------------------------------------------------------------------------%
+
+:- module mdb__set_cc.
+
+:- interface.
+:- import_module bool.
+
+:- type set_cc(T).
+
+:- pred set_cc__init(set_cc(T)).
+:- mode set_cc__init(uo) is det.
+
+:- pred set_cc__is_empty(set_cc(T)).
+:- mode set_cc__is_empty(in) is semidet.
+
+:- pred set_cc__member(T, set_cc(T), bool).
+:- mode set_cc__member(in, in, out) is cc_multi.
+
+:- pred set_cc__insert(set_cc(T), T, set_cc(T)).
+:- mode set_cc__insert(in, in, out) is cc_multi.
+
+:- pred set_cc__delete(set_cc(T), T, set_cc(T)).
+:- mode set_cc__delete(in, in, out) is cc_multi.
+
+%---------------------------------------------------------------------------%
+
+:- implementation.
+
+:- import_module std_util.
+:- import_module mdb__tree234_cc.
+
+:- type set_cc(T) == tree234_cc(T, unit).
+
+set_cc__init(S) :-
+	tree234_cc__init(S).
+
+set_cc__is_empty(S) :-
+	tree234_cc__is_empty(S).
+
+set_cc__member(T, S, Bool) :-
+	tree234_cc__search(S, T, Maybe),
+	(
+		Maybe = yes(_),
+		Bool = yes
+	;
+		Maybe = no,
+		Bool = no
+	).
+
+set_cc__insert(S0, T, S) :-
+	tree234_cc__set(S0, T, unit, S).
+
+set_cc__delete(S0, T, S) :-
+	tree234_cc__delete(S0, T, S).
+
Index: tests/debugger/declarative/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/Mmakefile,v
retrieving revision 1.48
diff -u -r1.48 Mmakefile
--- tests/debugger/declarative/Mmakefile	10 Oct 2002 19:43:59 -0000	1.48
+++ tests/debugger/declarative/Mmakefile	11 Oct 2002 05:30:51 -0000
@@ -24,6 +24,7 @@
 	ho2			\
 	ho3			\
 	ho4			\
+	ho5			\
 	if_then_else		\
 	input_term_dep		\
 	ite_2			\
@@ -47,12 +48,7 @@
 NONDEBUG_DECLARATIVE_PROGS=	\
 	untraced_subgoal
 
-# XXX 'ho5' fails due to an attempt to compare higher order terms.  This
-# happens because thrown exceptions are stored in a set, which uses builtin
-# comparison, and exceptions are not necessarily first order terms.
-#
 NONWORKING_DECLARATIVE_PROGS=	\
-	ho5
 
 # Some of the test cases require a different input in debug grades,
 # so we set INP to the appropriate extension to use for those tests.
@@ -171,8 +167,12 @@
 ho4.out: ho4 ho4.inp
 	$(MDB) ./ho4 < ho4.inp > ho4.out 2>&1
 
+# We need to pipe the output through sed to avoid hard-coding dependencies on
+# particular line numbers in the standard library source code.
 ho5.out: ho5 ho5.inp
-	$(MDB) ./ho5 < ho5.inp > ho5.out 2>&1
+	$(MDB) ./ho5 < ho5.inp 2>&1 | \
+		sed -e 's/exception.m:[0-9]*/exception.m:NNNN/g' \
+		> ho5.out 2>&1
 
 if_then_else.out: if_then_else if_then_else.inp
 	$(MDB) ./if_then_else < if_then_else.inp > if_then_else.out 2>&1
Index: tests/debugger/declarative/ho5.exp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/ho5.exp,v
retrieving revision 1.1
diff -u -r1.1 ho5.exp
--- tests/debugger/declarative/ho5.exp	10 Oct 2002 10:49:07 -0000	1.1
+++ tests/debugger/declarative/ho5.exp	11 Oct 2002 02:25:24 -0000
@@ -0,0 +1,48 @@
+       1:      1  1 CALL pred ho5:main/2-0 (cc_multi) ho5.m:8
+mdb> echo on
+Command echo enabled.
+mdb> register --quiet
+mdb> break p
+ 0: + stop  interface pred ho5:p/2-0 (det)
+mdb> continue
+       2:      2  2 CALL pred ho5:p/2-0 (det) ho5.m:18
+mdb> finish
+       9:      2  2 EXCP pred ho5:p/2-0 (det) c2; ho5.m:18
+mdb> dd
+Call p(1, _)
+Throws zero
+Expected? no
+q(1, 0)
+Valid? yes
+Call r(0, _)
+Throws zero
+Expected? yes
+Found unhandled exception:
+p(1, _)
+zero
+Is this a bug? yes
+       9:      2  2 EXCP pred ho5:p/2-0 (det) c2; ho5.m:18
+mdb> continue
+mdb: warning: reached unknown label
+This may result in some exception events
+being omitted from the trace.
+exception(univ_cons('<<function>>'))
+      10:      5  2 CALL pred ho5:p/2-0 (det) ho5.m:18
+mdb> finish
+      17:      5  2 EXCP pred ho5:p/2-0 (det) c2; ho5.m:18
+mdb> dd
+Call p(2, _)
+Throws zero
+Expected? no
+q(2, 0)
+Valid? yes
+Found unhandled exception:
+p(2, _)
+zero
+Is this a bug? yes
+      17:      5  2 EXCP pred ho5:p/2-0 (det) c2; ho5.m:18
+mdb> continue
+mdb: warning: reached unknown label
+This may result in some exception events
+being omitted from the trace.
+exception(univ_cons('<<function>>'))
Index: tests/debugger/declarative/ho5.exp2
===================================================================
RCS file: tests/debugger/declarative/ho5.exp2
diff -N tests/debugger/declarative/ho5.exp2
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/debugger/declarative/ho5.exp2	14 Oct 2002 06:31:02 -0000
@@ -0,0 +1,42 @@
+       1:      1  1 CALL pred ho5:main/2-0 (cc_multi) ho5.m:8
+mdb> echo on
+Command echo enabled.
+mdb> register --quiet
+mdb> break p
+ 0: + stop  interface pred ho5:p/2-0 (det)
+mdb> continue
+       3:      3  3 CALL pred ho5:p/2-0 (det) ho5.m:18 (exception.m:NNNN)
+mdb> finish
+      12:      3  3 EXCP pred ho5:p/2-0 (det) c2; ho5.m:18 (exception.m:NNNN)
+mdb> dd
+Call p(1, _)
+Throws zero
+Expected? no
+q(1, 0)
+Valid? yes
+Call r(0, _)
+Throws zero
+Expected? yes
+Found unhandled exception:
+p(1, _)
+zero
+Is this a bug? yes
+      12:      3  3 EXCP pred ho5:p/2-0 (det) c2; ho5.m:18 (exception.m:NNNN)
+mdb> continue
+exception(univ_cons('<<function>>'))
+      19:     10  3 CALL pred ho5:p/2-0 (det) ho5.m:18 (exception.m:NNNN)
+mdb> finish
+      28:     10  3 EXCP pred ho5:p/2-0 (det) c2; ho5.m:18 (exception.m:NNNN)
+mdb> dd
+Call p(2, _)
+Throws zero
+Expected? no
+q(2, 0)
+Valid? yes
+Found unhandled exception:
+p(2, _)
+zero
+Is this a bug? yes
+      28:     10  3 EXCP pred ho5:p/2-0 (det) c2; ho5.m:18 (exception.m:NNNN)
+mdb> continue
+exception(univ_cons('<<function>>'))
Index: tests/debugger/declarative/ho5.inp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/ho5.inp,v
retrieving revision 1.1
diff -u -r1.1 ho5.inp
--- tests/debugger/declarative/ho5.inp	10 Oct 2002 10:49:07 -0000	1.1
+++ tests/debugger/declarative/ho5.inp	11 Oct 2002 02:19:43 -0000
@@ -12,3 +12,6 @@
 finish
 dd
 no
+yes
+yes
+continue
--------------------------------------------------------------------------
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