[m-rev.] diff: generalize my mode analysis bug fix

Zoltan Somogyi zs at cs.mu.OZ.AU
Mon Oct 10 12:22:27 AEST 2005


compiler/modecheck_unify.m:
	Extend my recent bug fix to also handle the case where the problematic
	situation is not created by the state variable transformation.

tests/valid/state_var_mode_bug2.m:
	A new test case for this version of the bug.

tests/valid/Mmakefile:
	Enable the new test case.

Zoltan.

cvs diff: Diffing .
cvs diff: Diffing analysis
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/doc
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing boehm_gc/tests
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
Index: compiler/modecheck_unify.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/modecheck_unify.m,v
retrieving revision 1.89
diff -u -b -r1.89 modecheck_unify.m
--- compiler/modecheck_unify.m	7 Oct 2005 04:44:58 -0000	1.89
+++ compiler/modecheck_unify.m	8 Oct 2005 00:38:46 -0000
@@ -900,17 +900,17 @@
     % Optimize away unifications which always fail by replacing them with
     % `fail'.
     (
-        Unification = assign(AssignTarget, _),
+        Unification = assign(AssignTarget, AssignSource),
         mode_info_var_is_live(!.ModeInfo, AssignTarget, dead)
     ->
         Unify = conj([]),
-        record_optimize_away(GoalInfo, !ModeInfo)
+        record_optimize_away(GoalInfo, AssignTarget, AssignSource, !ModeInfo)
     ;
-        Unification = simple_test(_, _),
+        Unification = simple_test(TestVar1, TestVar2),
         Det = det
     ->
         Unify = conj([]),
-        record_optimize_away(GoalInfo, !ModeInfo)
+        record_optimize_away(GoalInfo, TestVar1, TestVar2, !ModeInfo)
     ;
         Det = failure
     ->
@@ -939,14 +939,26 @@
         Unify = unify(X, var(Y), ModeOfX - ModeOfY, Unification, UnifyContext)
     ).
 
-:- pred record_optimize_away(hlds_goal_info::in,
+    % If we optimize away a singleton variable in a unification in one branch
+    % of e.g. a switch, it is possible that the same variable is a singleton
+    % in another branch, but cannot be optimized away because it is bound in
+    % a call (which cannot be optimized away). In such cases, we must make sure
+    % that we call requantification to delete the variable from the nonlocals
+    % set of the switch, because otherwise, the arms of the switch would
+    % disagree on which nonlocals are bound.
+    %
+:- pred record_optimize_away(hlds_goal_info::in, prog_var::in, prog_var::in,
     mode_info::in, mode_info::out) is det.
 
-record_optimize_away(GoalInfo, !ModeInfo) :-
-    ( goal_info_has_feature(GoalInfo, dont_warn_singleton) ->
-        mode_info_need_to_requantify(!ModeInfo)
-    ;
+record_optimize_away(GoalInfo, Var1, Var2, !ModeInfo) :-
+    goal_info_get_nonlocals(GoalInfo, NonLocals),
+    (
+        set__member(Var1, NonLocals),
+        set__member(Var2, NonLocals)
+    ->
         true
+    ;
+        mode_info_need_to_requantify(!ModeInfo)
     ).
 
     % Modecheck_complicated_unify does some extra checks that are needed
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
cvs diff: Diffing debian/patches
cvs diff: Diffing deep_profiler
cvs diff: Diffing deep_profiler/notes
cvs diff: Diffing doc
cvs diff: Diffing extras
cvs diff: Diffing extras/aditi
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/concurrency
cvs diff: Diffing extras/curs
cvs diff: Diffing extras/curs/samples
cvs diff: Diffing extras/curses
cvs diff: Diffing extras/curses/sample
cvs diff: Diffing extras/dynamic_linking
cvs diff: Diffing extras/error
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/easyx
cvs diff: Diffing extras/graphics/easyx/samples
cvs diff: Diffing extras/graphics/mercury_glut
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/gears
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/lazy_evaluation
cvs diff: Diffing extras/lex
cvs diff: Diffing extras/lex/samples
cvs diff: Diffing extras/lex/tests
cvs diff: Diffing extras/logged_output
cvs diff: Diffing extras/moose
cvs diff: Diffing extras/moose/samples
cvs diff: Diffing extras/moose/tests
cvs diff: Diffing extras/morphine
cvs diff: Diffing extras/morphine/non-regression-tests
cvs diff: Diffing extras/morphine/scripts
cvs diff: Diffing extras/morphine/source
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/posix
cvs diff: Diffing extras/quickcheck
cvs diff: Diffing extras/quickcheck/tutes
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/solver_types
cvs diff: Diffing extras/solver_types/library
cvs diff: Diffing extras/stream
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing extras/xml
cvs diff: Diffing extras/xml/samples
cvs diff: Diffing extras/xml_stylesheets
cvs diff: Diffing java
cvs diff: Diffing java/runtime
cvs diff: Diffing library
cvs diff: Diffing mdbcomp
cvs diff: Diffing profiler
cvs diff: Diffing robdd
cvs diff: Diffing runtime
cvs diff: Diffing runtime/GETOPT
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing samples/solutions
cvs diff: Diffing samples/tests
cvs diff: Diffing samples/tests/c_interface
cvs diff: Diffing samples/tests/c_interface/c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/tests/c_interface/mercury_calls_c
cvs diff: Diffing samples/tests/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/tests/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/tests/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/tests/diff
cvs diff: Diffing samples/tests/muz
cvs diff: Diffing samples/tests/rot13
cvs diff: Diffing samples/tests/solutions
cvs diff: Diffing samples/tests/toplevel
cvs diff: Diffing scripts
cvs diff: Diffing slice
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
cvs diff: Diffing tests/debugger/declarative
cvs diff: Diffing tests/dppd
cvs diff: Diffing tests/general
cvs diff: Diffing tests/general/accumulator
cvs diff: Diffing tests/general/string_format
cvs diff: Diffing tests/general/structure_reuse
cvs diff: Diffing tests/grade_subdirs
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/exceptions
cvs diff: Diffing tests/hard_coded/purity
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/invalid/purity
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/mmc_make
cvs diff: Diffing tests/mmc_make/lib
cvs diff: Diffing tests/recompilation
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/valid
Index: tests/valid/Mmakefile
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/valid/Mmakefile,v
retrieving revision 1.158
diff -u -b -r1.158 Mmakefile
--- tests/valid/Mmakefile	7 Oct 2005 04:45:01 -0000	1.158
+++ tests/valid/Mmakefile	7 Oct 2005 08:02:24 -0000
@@ -187,6 +187,7 @@
 	stack_opt_simplify \
 	state_var_bug \
 	state_var_mode_bug \
+	state_var_mode_bug2 \
 	static \
 	subtype_switch \
 	switch_detection_bug \
Index: tests/valid/state_var_mode_bug2.m
===================================================================
RCS file: tests/valid/state_var_mode_bug2.m
diff -N tests/valid/state_var_mode_bug2.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/valid/state_var_mode_bug2.m	10 Oct 2005 02:21:39 -0000
@@ -0,0 +1,96 @@
+%-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et
+%-----------------------------------------------------------------------------%
+%
+% Author: Ralph Becket <rafe at cs.mu.oz.au>
+%
+% This is a regression test for a bug involving the interaction of the mode
+% system and quantification, triggered by the state variable transformation.
+%
+% This version expands out the state variable transformation.
+%
+%-----------------------------------------------------------------------------%
+
+:- module state_var_mode_bug2.
+
+:- interface.
+
+:- import_module bool, int.
+
+:- pred p(bool::in, bool::in, int::in, int::out) is semidet.
+
+:- implementation.
+
+p(A, B, !Y) :-
+    some [X0, _X] (
+        p0(X0),
+        p2(X0, X1),
+        p2(X1, X2),
+        (
+            A = yes
+        ->
+            (
+                B = yes,
+                p1(X2),
+                p2(X2, X3),
+                p1(X3),
+                X4 = X3
+            ;
+                B = no,
+                (
+                    p1(X2),
+                    p2(X2, X3)
+                ->
+                    p1(X3),
+                    X4 = X3
+                ;
+                    X4 = X2
+                )
+            ),
+            X5 = X4
+        ;
+            (
+                p1(X2),
+                p2(X2, X3)
+            ->
+                (
+                    A = yes,
+                    p1(X3),
+                    p2(X3, X4),
+                    (
+                        B = yes,
+                        p2(X4, X5)
+                    ;
+                        B = no,
+                        X5 = X4
+                    )
+                ;
+                    A = no,
+                    X5 = X3
+                )
+            ;
+                p1(X2)
+            ->
+                p1(X2),
+                p2(X2, X3),
+                p1(X3),
+                X5 = X3
+            ;
+                X5 = X2
+            )
+        ),
+        _X = X5
+    ).
+
+:- pred p0(int::out) is det.
+
+p0(0).
+
+:- pred p1(int::in) is semidet.
+
+p1(1).
+
+:- pred p2(int::in, int::out) is semidet.
+
+p2(X0, X0) :-
+    p1(X0).
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trace
cvs diff: Diffing util
cvs diff: Diffing vim
cvs diff: Diffing vim/after
cvs diff: Diffing vim/ftplugin
cvs diff: Diffing vim/syntax
--------------------------------------------------------------------------
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