[m-rev.] for review / comment: simplify code in solutions.m

Julien Fischer juliensf at csse.unimelb.edu.au
Tue Nov 30 22:59:36 AEDT 2010


Hi,

I would like opinions as to whether the following diff constitutes an
acceptable abuse of the promise_equivalent_solutions mechanism.
(A similar change could be made to get_one_solution etc, in builtin.m
which would then remove the need for a bunch of foreign_procs.)

Julien.

-----------------

Branches: main

library/solutions.m:
 	Simplify the implementation of non_cc_call/{4,5}; in
 	particular avoid the construction of a closure.

Index: library/solutions.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/solutions.m,v
retrieving revision 1.8
diff -u -r1.8 solutions.m
--- library/solutions.m	30 Nov 2010 06:51:10 -0000	1.8
+++ library/solutions.m	30 Nov 2010 11:49:05 -0000
@@ -396,15 +396,15 @@
  non_cc_call(P::pred(in, in, out) is det, X::in, !.Acc::in, !:Acc::out) :-
      P(X, !Acc).
  non_cc_call(P::pred(in, in, out) is cc_multi, X::in, !.Acc::in, !:Acc::out) :-
-    Pred = (pred(Soln::out) is cc_multi :-
-        P(X, !.Acc, Soln)
-    ),
-    impure !:Acc = builtin.get_one_solution(Pred).
+    promise_equivalent_solutions [!:Acc] (
+        P(X, !Acc),
+        impure impure_true
+    ).
  non_cc_call(P::pred(in, di, uo) is cc_multi, X::in, !.Acc::di, !:Acc::uo) :-
-    Pred = (pred({}::out, !.Acc::di, !:Acc::uo) is cc_multi :-
-        P(X, !Acc)
-    ),
-    impure builtin.get_one_solution_io(Pred, _, !Acc).
+    promise_equivalent_solutions [!:Acc] (
+        P(X, !Acc),
+        impure impure_true
+    ).
  non_cc_call(P::pred(in, di, uo) is det, X::in, !.Acc::di, !:Acc::uo) :-
      P(X, !Acc).
  non_cc_call(P::pred(mdi, di, uo) is det, X::mdi, !.Acc::di, !:Acc::uo) :-
@@ -421,14 +421,14 @@
          !.Acc::di, !:Acc::uo) :-
      P(X, More, !Acc).
  non_cc_call(P::pred(in, out, in, out) is det, X::in, More::out,
-        Acc0::in, Acc::out) :-
-    P(X, More, Acc0, Acc).
+        !.Acc::in, !:Acc::out) :-
+    P(X, More, !Acc).
  non_cc_call(P::pred(in, out, di, uo) is cc_multi, X::in, More::out,
          !.Acc::di, !:Acc::uo) :-
-    Pred = (pred(M::out, !.Acc::di, !:Acc::uo) is cc_multi :-
-        P(X, M, !Acc)
-    ),
-    impure builtin.get_one_solution_io(Pred, More, !Acc).
+    promise_equivalent_solutions [More, !:Acc] (
+        P(X, More, !Acc),
+        impure impure_true
+    ).

  :- type heap_ptr == private_builtin.heap_pointer.
  :- type trail_ptr ---> trail_ptr(c_pointer).

--------------------------------------------------------------------------
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