[m-dev.] for review: fix switch-detection bug
Simon Taylor
stayl at cs.mu.OZ.AU
Tue Aug 31 12:51:05 AEST 1999
> The unfortunate thing about this change is that it breaks backwards
> compatibility with 0.8. Because of this, I think it probably deserves
> to be mentioned in the NEWS file.
Estimated hours taken: 1
compiler/switch_detection.m:
Fix a bug - the code was looking for switch deconstructions
after the first call in each branch. Doing this can remove
infinite loops, which the strict sequential semantics does
not allow.
NEWS:
Discuss the backwards incompatibility effects of this change.
doc/reference_manual.texi:
Add some more documentation about where the test unifications
in switches can occur.
tests/invalid/Mmakefile:
tests/invalid/not_a_switch.m:
Test case.
Index: NEWS
===================================================================
RCS file: /home/staff/zs/imp/mercury/NEWS,v
retrieving revision 1.144
diff -u -u -r1.144 NEWS
--- NEWS 1999/07/14 04:28:01 1.144
+++ NEWS 1999/08/31 02:29:05
@@ -97,6 +97,22 @@
Changes to the Mercury implementation:
**************************************
+* We've fixed a bug in switch detection.
+
+ This change may break some code written for Mercury 0.8. Some
+ disjunctions which Mercury 0.8 found to have determinism `det'
+ now have determinism `nondet'.
+
+ Mercury 0.8 (but not Mercury 0.7) allowed switches where a unification
+ to test the switched-on variable against a function symbol occurred after
+ the first call in the disjunct. Doing this may remove infinite loops,
+ violating the strict sequential semantics (see the "Semantics" chapter
+ of the Mercury Language Reference Manual).
+
+ To fix switches for which determinism errors are now reported simply
+ reorder the goals in each disjunct so that only unifications occur
+ before the test of the switched-on variable.
+
* The Mercury debugger (mdb) now includes support for interactive queries.
See the "Interactive query commands" subsection of the "Debugger commands"
Index: doc/reference_manual.texi
===================================================================
RCS file: /home/staff/zs/imp/mercury/doc/reference_manual.texi,v
retrieving revision 1.149
diff -u -u -r1.149 reference_manual.texi
--- reference_manual.texi 1999/08/04 06:19:45 1.149
+++ reference_manual.texi 1999/08/31 02:31:28
@@ -1861,6 +1861,34 @@
A switch can succeed at most zero times
only if all arms of the switch can succeed at most zero times.
+Only unifications may occur before the test of the switched-on variable
+in each disjunct. Tests of the switched-on variable may occur within
+existential quantification goals.
+
+The following example is a switch.
+
+ at example
+(
+ Out = 1, L = []
+;
+ some [H, T] (
+ L = [H|T],
+ nonempty(H, T, Out)
+ )
+)
+ at end example
+
+The following example is not a switch because the call in the first
+disjunct occurs before the test of the switched-on variable.
+
+ at example
+(
+ empty(Out), L = []
+;
+ L = [H|T], nonempty(H, T, Out)
+)
+ at end example
+
@item Disjunctions
The determinism of the empty disjunction (the goal @samp{fail})
is @code{failure}.
> Would it be worth adding an option, e.g. `--backwards-compat 0.8',
> that would preserve the old behaviour, in case anyone had written
> code that relied on it?
Probably not, because fixing affected code is trivial. It's just as
simple to fix the code as to use an option to disable the error messages.
By the way, the problem wasn't introduced in the revision you pointed out.
It was introduced in revision 1.81 of switch_detection.m, where the ability
to search for deconstructions in existential qualifications was added.
My fix (revision 1.84) to the bug introduced by that change was not correct,
and in fact made cse_detection.m use the same buggy test as switch_detection.m
when finding common deconstructions.
Simon.
--------------------------------------------------------------------------
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