[m-rev.] for review: fix bug #226 - incorrect purity of lazy.read_if_val/2

Julien Fischer jfischer at opturion.com
Tue Jan 8 11:06:21 AEDT 2013


For review by Paul.

The comments in the bug report mentioned that we were awaiting some changes
to the deep profiler before doing this, but since there is currently
only a single
call to read_if_val/2 in the deep profiler, I assume that these have been done.

I'm not sure that the purity promise in deep_profiler/autopar_types.m is in the
correct spot -- it's currently equivalent to the existing code except
the impurity
is no explicit.

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

Fix bug #226: the library predicate lazy.read_if_val/2 was incorrectly declared
as pure.  The reason for it being impure rather than semipure is to avoid any
goals containing calls to force/1 being reordered with respect to it.

library/lazy.m:
    Make read_if_val/2 as impure.

deep_profiler/autopar_types.m:
     Confrom to the above change.

Julien.

diff --git a/deep_profiler/autopar_types.m b/deep_profiler/autopar_types.m
index 5d101b1..9565b6c 100644
--- a/deep_profiler/autopar_types.m
+++ b/deep_profiler/autopar_types.m
@@ -310,14 +310,16 @@
pard_goal_detail_annon_to_pard_goal_annon(SharedVarsSet, PGD, PG) :-
     assoc_list(var_rep, float)::in, assoc_list(var_rep, float)::out) is det.

 build_var_use_list(Map, Var, !List) :-
-    (
-        map.search(Map, Var, LazyUse),
-        read_if_val(LazyUse, Use)
-    ->
-        UseTime = Use ^ vui_cost_until_use,
-        !:List = [Var - UseTime | !.List]
-    ;
-        true
+    promise_pure (
+        (
+            map.search(Map, Var, LazyUse),
+            impure read_if_val(LazyUse, Use)
+        ->
+            UseTime = Use ^ vui_cost_until_use,
+            !:List = [Var - UseTime | !.List]
+        ;
+            true
+        )
     ).

 %-----------------------------------------------------------------------------%
diff --git a/library/lazy.m b/library/lazy.m
index a42bfce..9979f72 100644
--- a/library/lazy.m
+++ b/library/lazy.m
@@ -69,7 +69,7 @@
     % with force/1 This is useful as it can provide information without
     % incurring (much) cost.
     %
-:- semipure pred read_if_val(lazy(T)::in, T::out) is semidet.
+:- impure pred read_if_val(lazy(T)::in, T::out) is semidet.

     % Test lazy values for equality.
     %
@@ -169,9 +169,7 @@ read_if_val(Lazy, Value) :-
     promise_equivalent_solutions [Mutvar] (
         Lazy = lazy(Mutvar)
     ),
-    promise_semipure (
-        impure get_mutvar(Mutvar, State),
-        State = value(Value)
-    ).
+    impure get_mutvar(Mutvar, State),
+    State = value(Value).

 %-----------------------------------------------------------------------------%



More information about the reviews mailing list