[m-rev.] for post-commit review: fix magicbox.m

Zoltan Somogyi zs at cs.mu.OZ.AU
Thu Apr 1 14:32:05 AEST 2004


compiler/det_analysis.m:
	Fix an overly strong sanity check, at least temporarily.

tests/invalid/magicbox.m:
	Add the test case motivating that change.

tests/invalid/MMakefile
	Enable the new test.

Zoltan.

Index: compiler/det_analysis.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/det_analysis.m,v
retrieving revision 1.163
diff -u -b -r1.163 det_analysis.m
--- compiler/det_analysis.m	31 Oct 2003 03:27:21 -0000	1.163
+++ compiler/det_analysis.m	1 Apr 2004 04:30:05 -0000
@@ -1093,6 +1093,10 @@
 % the goal might have many logical solutions if there were no
 % pruning, but that the goal occurs in a single-solution
 % context, so only the first solution will be returned.
+%
+% The reason why we don't throw an exception in det_switch_maxsoln and
+% det_disjunction_maxsoln is given in the documentation of the test case
+% invalid/magicbox.m.
 
 :- pred det_conjunction_maxsoln(soln_count, soln_count, soln_count).
 :- mode det_conjunction_maxsoln(in, in, out) is det.
@@ -1141,19 +1145,11 @@
 det_disjunction_maxsoln(at_most_many_cc, at_most_zero,    at_most_many_cc).
 det_disjunction_maxsoln(at_most_many_cc, at_most_one,     at_most_many_cc).
 det_disjunction_maxsoln(at_most_many_cc, at_most_many_cc, at_most_many_cc).
-det_disjunction_maxsoln(at_most_many_cc, at_most_many,    _) :-
-	% if the first disjunct could be cc pruned,
-	% the second disjunct ought to have been cc pruned too
-	error("det_disjunction_maxsoln: cc in first case, " ++
-		"not cc in second case").
+det_disjunction_maxsoln(at_most_many_cc, at_most_many,    at_most_many_cc).
 
 det_disjunction_maxsoln(at_most_many,    at_most_zero,    at_most_many).
 det_disjunction_maxsoln(at_most_many,    at_most_one,     at_most_many).
-det_disjunction_maxsoln(at_most_many,    at_most_many_cc, _) :-
-	% if the first disjunct could be cc pruned,
-	% the second disjunct ought to have been cc pruned too
-	error("det_disjunction_maxsoln: cc in second case, " ++
-		"not cc in first case").
+det_disjunction_maxsoln(at_most_many,    at_most_many_cc, at_most_many_cc).
 det_disjunction_maxsoln(at_most_many,    at_most_many,    at_most_many).
 
 det_disjunction_canfail(can_fail,    can_fail,    can_fail).
@@ -1174,17 +1170,11 @@
 det_switch_maxsoln(at_most_many_cc, at_most_zero,    at_most_many_cc).
 det_switch_maxsoln(at_most_many_cc, at_most_one,     at_most_many_cc).
 det_switch_maxsoln(at_most_many_cc, at_most_many_cc, at_most_many_cc).
-det_switch_maxsoln(at_most_many_cc, at_most_many,    _) :-
-	% if the first case could be cc pruned,
-	% the second case ought to have been cc pruned too
-	error("det_switch_maxsoln: cc in first case, not cc in second case").
+det_switch_maxsoln(at_most_many_cc, at_most_many,    at_most_many_cc).
 
 det_switch_maxsoln(at_most_many,    at_most_zero,    at_most_many).
 det_switch_maxsoln(at_most_many,    at_most_one,     at_most_many).
-det_switch_maxsoln(at_most_many,    at_most_many_cc, _) :-
-	% if the first case could be cc pruned,
-	% the second case ought to have been cc pruned too
-	error("det_switch_maxsoln: cc in second case, not cc in first case").
+det_switch_maxsoln(at_most_many,    at_most_many_cc, at_most_many_cc).
 det_switch_maxsoln(at_most_many,    at_most_many,    at_most_many).
 
 det_switch_canfail(can_fail,    can_fail,    can_fail).
cvs diff: Diffing tests/invalid
Index: tests/invalid/Mmakefile
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/invalid/Mmakefile,v
retrieving revision 1.150
diff -u -b -r1.150 Mmakefile
--- tests/invalid/Mmakefile	9 Mar 2004 09:09:54 -0000	1.150
+++ tests/invalid/Mmakefile	1 Apr 2004 04:15:24 -0000
@@ -60,17 +60,17 @@
 	errors \
 	errors1 \
 	errors2 \
+	exported_mode \
 	external \
 	ext_type \
 	ext_type_bug \
-	exported_mode \
 	field_syntax_error \
 	foreign_singleton \
 	foreign_type_2 \
 	foreign_type_visibility \
+	freefree \
 	func_errors \
 	funcs_as_preds \
-	freefree \
 	ho_default_func_1 \
 	ho_default_func_3 \
 	ho_type_mode_bug \
@@ -83,6 +83,7 @@
 	invalid_typeclass \
 	io_in_ite_cond \
 	lambda_syntax_error \
+	magicbox \
 	make_opt_error \
 	merge_ground_any \
 	method_impl \
@@ -92,8 +93,8 @@
 	modes_erroneous \
 	mostly_uniq1 \
 	mostly_uniq2 \
-	multimode_missing_impure \
 	multimode_dcg \
+	multimode_missing_impure \
 	multimode_syntax \
 	multisoln_func \
 	nested_impl_in_int \
@@ -120,31 +121,31 @@
 	tc_err1 \
 	tc_err2 \
 	tricky_assert1 \
-	type_inf_loop \
-	type_loop \
-	type_mismatch \
-	type_vars \
 	typeclass_bogus_method \
 	typeclass_constraint_extra_var \
-	typeclass_mode \
 	typeclass_missing_det \
 	typeclass_missing_det_2 \
 	typeclass_missing_det_3 \
 	typeclass_missing_mode \
 	typeclass_missing_mode_2 \
+	typeclass_mode \
 	typeclass_test_1 \
+	typeclass_test_10 \
 	typeclass_test_2 \
 	typeclass_test_3 \
 	typeclass_test_4 \
 	typeclass_test_5 \
 	typeclass_test_7 \
 	typeclass_test_9 \
-	typeclass_test_10 \
+	type_inf_loop \
+	type_loop \
+	type_mismatch \
 	types	\
+	type_vars \
 	unbound_type_vars \
 	undeclared_mode \
-	undef_lambda_mode \
 	undef_inst \
+	undef_lambda_mode \
 	undef_mode \
 	undef_mode_and_no_clauses \
 	undef_symbol \
Index: tests/invalid/magicbox.err_exp
===================================================================
RCS file: tests/invalid/magicbox.err_exp
diff -N tests/invalid/magicbox.err_exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/invalid/magicbox.err_exp	1 Apr 2004 04:24:43 -0000
@@ -0,0 +1,6 @@
+magicbox.m:036: In `arguments_handler(di, uo, out)':
+magicbox.m:036:   error: determinism declaration not satisfied.
+magicbox.m:036:   Declared `cc_multi', inferred `cc_nondet'.
+magicbox.m:055:   call to `to_int(in, out)' can fail.
+magicbox.m:062:   call to `to_int(in, out)' can fail.
+For more information, try recompiling with `-E'.
Index: tests/invalid/magicbox.m
===================================================================
RCS file: tests/invalid/magicbox.m
diff -N tests/invalid/magicbox.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/invalid/magicbox.m	1 Apr 2004 04:18:50 -0000
@@ -0,0 +1,71 @@
+%------------------------------------------------------------------------------%
+% This test case is a cut down version of magicbox.m:
+%
+%	Gillian Tee		: pptee at cs.mu.oz.au
+%	Leslie Gondor	: leslieg at cs.mu.oz.au
+%
+%	433-481 - Agent Programming Languages - Project 1
+%	Department of Computer Science and Software Engineering
+%	The University of Melbourne
+%	March/April, 2004
+%	
+%------------------------------------------------------------------------------%
+%
+% The problem this test case tests for is an overstrong sanity check in
+% determinism analysis. The problem scenario is as follows:
+%
+% 1. The arguments_handler predicate is in a first_soln context.
+% 2. So is the outer if-then-else, and its then-part and else-part.
+% 3. The then-part, the call to string.to_int, can fail.
+% 4. The condition of the other if-then-else is thus in an all_soln context.
+% 5. Parts 3 and 4 also hold for the inner if-then-else, making it naturally
+%    nondet, which is converted into cc_nondet by its being inside a first_soln
+%    context.
+% 6. The then part of the outer if-then-else is semidet, the else part is
+%    cc_nondet. The sanity check complains that only one of the two arms of the
+%    switch seems to be in first_soln context. It doesn't see that the then
+%    part is in a first_soln context too; its detism doesn't say that.
+
+:- module magicbox.
+
+:- interface.
+
+:- import_module io.
+
+:- pred arguments_handler( io.state, io.state, int ).
+:- mode arguments_handler( di,       uo      , out   ) is cc_multi.
+
+%------------------------------------------------------------------------------%
+
+:- implementation.
+
+:- import_module list.
+:- import_module string.
+
+arguments_handler( !IO, Length ) :-
+	% Check for correct command-line arguments:
+	io.command_line_arguments( Arguments, !IO ),
+	
+	( 
+		(	% Valid arguments - Scenario 1
+			list.member( "-1", Arguments, ArgsSubS1 ),
+			list.index0( ArgsSubS1, 1, LengthStr )
+		) ->
+		(
+			string.to_int( LengthStr, Length )
+		);
+		(	% Valid arguments - Scenario 2
+			list.member( "-2", Arguments, ArgsSubS2 ),
+			list.index0( ArgsSubS2, 2, LengthStr )
+		) ->
+		(
+			string.to_int( LengthStr, Length )
+		);
+		(
+			Length = 0
+		)
+	).
+
+%------------------------------------------------------------------------------%
+% EOF
+%------------------------------------------------------------------------------%
cvs diff: Diffing tests/invalid/purity
--------------------------------------------------------------------------
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