diff: bug fix for reordering + unique modes problem
Fergus Henderson
fjh at cs.mu.OZ.AU
Wed Jan 21 16:39:51 AEDT 1998
Tom, you might like to have a look at this one.
Estimated hours taken: 4
Fix a bug that caused the compiler to report spurious unique mode
errors for cases involving nested conjunctions, reordering, and
unique modes.
compiler/modes.m:
When modechecking conjunctions, if the conjunction as a whole
delays, make sure that we restore the original live_vars set.
compiler/mode_info.m:
Add mode_info_get_live_vars/2 and mode_info_set_live_vars/3,
for use by modes.m.
tests/hard_coded/Mmakefile:
tests/hard_coded/reorder_di.m:
tests/hard_coded/reorder_di.exp:
Regression test for the above-mentioned bug.
cvs -n diff compiler/mode_info.m compiler/modes.m tests/hard_coded/Mmakefile tests/hard_coded/reorder_di.exp tests/hard_coded/reorder_di.m
Index: compiler/mode_info.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mode_info.m,v
retrieving revision 1.42
diff -u -r1.42 mode_info.m
--- mode_info.m 1998/01/13 10:03:09 1.42
+++ mode_info.m 1998/01/20 13:35:56
@@ -191,6 +191,12 @@
:- pred mode_info_set_delay_info(delay_info, mode_info, mode_info).
:- mode mode_info_set_delay_info(in, mode_info_di, mode_info_uo) is det.
+:- pred mode_info_get_live_vars(mode_info, list(set(var))).
+:- mode mode_info_get_live_vars(mode_info_ui, out) is det.
+
+:- pred mode_info_set_live_vars(list(set(var)), mode_info, mode_info).
+:- mode mode_info_set_live_vars(in, mode_info_di, mode_info_uo) is det.
+
:- pred mode_info_get_nondet_live_vars(mode_info, list(set(var))).
:- mode mode_info_get_nondet_live_vars(mode_info_no_io, out) is det.
@@ -598,6 +604,13 @@
mode_info_get_liveness_2([LiveVarsSet | LiveVarsList], LiveVars0, LiveVars) :-
set__union(LiveVars0, LiveVarsSet, LiveVars1),
mode_info_get_liveness_2(LiveVarsList, LiveVars1, LiveVars).
+
+mode_info_get_live_vars(mode_info(_,_,_,_,_,_,_,_,_,_,_,_,LiveVarsList,_,_,_),
+ LiveVarsList).
+
+mode_info_set_live_vars(LiveVarsList,
+ mode_info(A,B,C,D,E,F,G,H,I,J,K,L,_,N,O,P),
+ mode_info(A,B,C,D,E,F,G,H,I,J,K,L,LiveVarsList,N,O,P)).
%-----------------------------------------------------------------------------%
Index: compiler/modes.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modes.m,v
retrieving revision 1.214
diff -u -r1.214 modes.m
--- modes.m 1998/01/13 10:13:01 1.214
+++ modes.m 1998/01/20 13:57:50
@@ -1084,6 +1084,7 @@
{ mode_info_get_errors(ModeInfo0, OldErrors) },
mode_info_set_errors([]),
+ { mode_info_get_live_vars(ModeInfo0, LiveVars0) },
{ mode_info_get_delay_info(ModeInfo0, DelayInfo0) },
{ delay_info__enter_conj(DelayInfo0, DelayInfo1) },
mode_info_set_delay_info(DelayInfo1),
@@ -1100,6 +1101,14 @@
{ delay_info__leave_conj(DelayInfo4, DelayedGoals, DelayInfo5) },
mode_info_set_delay_info(DelayInfo5),
+ ( { DelayedGoals \= [] } ->
+ % the variables in the delayed goals should not longer
+ % be considered live (the conjunction itself will
+ % delay, and its nonlocals will be made live)
+ mode_info_set_live_vars(LiveVars0)
+ ;
+ []
+ ),
% we only report impurity errors if there were no other errors
( { DelayedGoals = [] } ->
% XXX perhaps we should report all the impurity errors,
@@ -1158,7 +1167,7 @@
{ ImpurityErrors1 = ImpurityErrors0 }
),
- % Hang onto the original instmap & delay_info
+ % Hang onto the original instmap, delay_info, and live_vars
mode_info_dcg_get_instmap(InstMap0),
=(ModeInfo0),
{ mode_info_get_delay_info(ModeInfo0, DelayInfo0) },
Index: tests/hard_coded/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/Mmakefile,v
retrieving revision 1.7
diff -u -r1.7 Mmakefile
--- Mmakefile 1998/01/16 07:05:48 1.7
+++ Mmakefile 1998/01/21 05:34:36
@@ -53,6 +53,7 @@
qual_adv_test \
qual_basic_test \
qual_is_test \
+ reorder_di \
reverse_arith \
string_alignment \
string_loop \
Index: tests/hard_coded/reorder_di.exp
===================================================================
RCS file: reorder_di.exp
diff -N reorder_di.exp
--- /dev/null Wed Jan 21 16:37:24 1998
+++ reorder_di.exp Wed Jan 21 16:33:46 1998
@@ -0,0 +1,4 @@
+foo
+foo
+quux
+bar
Index: tests/hard_coded/reorder_di.m
===================================================================
RCS file: reorder_di.m
diff -N reorder_di.m
--- /dev/null Wed Jan 21 16:37:24 1998
+++ reorder_di.m Wed Jan 21 16:32:28 1998
@@ -0,0 +1,36 @@
+% regression test - Mercury 0.7 failed this test
+
+:- module reorder_di.
+
+:- interface.
+
+:- import_module io.
+
+:- pred main(io__state::di, io__state::uo) is det.
+
+:- implementation.
+
+:- import_module require.
+
+main -->
+ { r(Y) },
+ { q(X) },
+ io__write_string(Str),
+ ( { Y = 1 } ->
+ io__write_string(Str),
+ io__write_string("quux\n")
+ ;
+ { error("qux") }
+ ),
+ io__write_string("bar\n"),
+ { X = 1, Str = "foo\n"
+ ; X = 2, Str = "baz\n"
+ }.
+
+:- pred q(int::(free -> bound(1 ; 2))) is det.
+
+q(1).
+
+:- pred r(int::(free -> bound(1 ; 2))) is det.
+
+r(1).
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
More information about the developers
mailing list