[m-rev.] diff: fix bug in dependent parallel conjunction transform

Peter Wang wangp at students.csse.unimelb.edu.au
Thu Oct 19 22:48:10 AEST 2006


Estimated hours taken: 0.25
Branches: main

When pushing `signal' calls into predicates we mustn't forget there may be
further references to a signalled variable after the `signal' call.  So we
need to insert `get' calls, as we do when pushing `wait' calls.

    p(X::out), signal(FutureX, X), q(X, Y), ...
=>
    'Parallel__p__[1]'(FutureX), get(FutureX, X), q(X, Y), ...


compiler/dep_par_conj.m:
	Fix the bug as above.

tests/par_conj/Mmakefile:
tests/par_conj/dep_par_29.exp:
tests/par_conj/dep_par_29.m:
	Add a test case.


Index: compiler/dep_par_conj.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/dep_par_conj.m,v
retrieving revision 1.11
diff -u -r1.11 dep_par_conj.m
--- compiler/dep_par_conj.m	31 Aug 2006 08:43:33 -0000	1.11
+++ compiler/dep_par_conj.m	19 Oct 2006 12:23:08 -0000
@@ -1196,15 +1196,16 @@
         else
             replace_call(WaitPairs, SignalPairs, Goal0, Goal, !Info),
 
-            % After the replaced call may be further references to a waited
-            % variable.  Add `get' goals after the transformed goal (a get
-            % is a wait without the waiting).  We assume the get goals will
+            % After the replaced call may be further references to a signalled
+            % or waited variable.  Add `get' goals after the transformed goal
+            % to make sure the variable is bound.  We assume the get goals will
             % be simplified away if they turn out to be unnecessary.
             %
             % XXX the simplify pass that comes later doesn't always remove
             %     these calls even if they're unnecessary
             %
-            list.map(make_get_goal(!.Info ^ dp_module_info), WaitPairs, GetGoals),
+            list.map(make_get_goal(!.Info ^ dp_module_info),
+                SignalPairs ++ WaitPairs, GetGoals),
 
             RevGoals = GetGoals ++ [Goal] ++ IrrelevantWaitGoals ++ RevGoals1,
             FwdGoals = IrrelevantSignalGoals ++ FwdGoals1
Index: tests/par_conj/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/par_conj/Mmakefile,v
retrieving revision 1.8
diff -u -r1.8 Mmakefile
--- tests/par_conj/Mmakefile	11 Sep 2006 05:37:08 -0000	1.8
+++ tests/par_conj/Mmakefile	19 Oct 2006 12:32:36 -0000
@@ -45,7 +45,8 @@
 	dep_par_25b \
 	dep_par_26 \
 	dep_par_27 \
-	dep_par_28
+	dep_par_28 \
+	dep_par_29
 
 INDEP_PAR_CONJ_PROGS = \
 	indep_par_append \
Index: tests/par_conj/dep_par_29.exp
===================================================================
RCS file: tests/par_conj/dep_par_29.exp
diff -N tests/par_conj/dep_par_29.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/par_conj/dep_par_29.exp	19 Oct 2006 12:30:08 -0000
@@ -0,0 +1 @@
+{1, 11, 11}
Index: tests/par_conj/dep_par_29.m
===================================================================
RCS file: tests/par_conj/dep_par_29.m
diff -N tests/par_conj/dep_par_29.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/par_conj/dep_par_29.m	19 Oct 2006 12:32:19 -0000
@@ -0,0 +1,30 @@
+:- module dep_par_29.
+
+:- interface.
+:- import_module io.
+
+:- pred main(io::di, io::uo) is det.
+
+:- implementation.
+:- import_module int.
+
+main(!IO) :-
+    (
+        p(X),
+        % We were missing a get(FutureX, X) call here.
+        % It's needed because the signal(FutureX, X) call is
+        % pushed into p, so X isn't bound anywhere.
+        q(X, Y)
+    &
+        q(X, Z)
+    ),
+    io.print({X,Y,Z}, !IO),
+    io.nl(!IO).
+
+:- pred p(int::out) is det.
+:- pragma no_inline(p/1).
+p(1).
+
+:- pred q(int::in, int::out) is det.
+:- pragma no_inline(q/2).
+q(X,X+10).
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list