[m-dev.] Re: [leslieg at ugrad.unimelb.edu.au: Assertion failure in Mercury compiler]

Zoltan Somogyi zs at cs.mu.OZ.AU
Wed Mar 31 21:59:06 AEST 2004


On 31-Mar-2004, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> Are you working on this?
> 
> I would have a look at it myself, except that legally I can't fix it until
> I get a non-Galois computer.

Here is the minimized test case, and the diagnosis. I see three possible fixes.
One is to eliminate the sanity check, as shown in the diff to det_analysis.m
below; this yields a reasonable error message instead of a compiler abort.
The second is to change the rules of determinism analysis so that if
a goal is in a first_solution context, then we coerce its detism from
fail and semidet to cc_nondet and from erroneous and det to cc_multi;
I don't think this works because we lose info about erroneous.
The third is to add cc_ versions of not only nondet and multi but also
of failure, semidet, erroneous and det.

Any opinions?

Zoltan.

%------------------------------------------------------------------------------%
% 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
		)
	).

%------------------------------------------------------------------------------%

Index: 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
--- det_analysis.m	31 Oct 2003 03:27:21 -0000	1.163
+++ det_analysis.m	31 Mar 2004 11:37:26 -0000
@@ -1141,19 +1141,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 +1166,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).
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list