[m-rev.] diff: fix compilation of extras/solver_types/library

Julien Fischer juliensf at cs.mu.OZ.AU
Thu Nov 10 14:06:51 AEDT 2005


Estimated hours taken: 0.25
Branches: main

Fix compilation of the `any' library in the extras distribution.

XXX Ralph, the compiler is not correctly propagating impurity
out from negated contexts - this library contains numerous examples.

extras/solver_types/library/*.m
	Place impurity annotations on goals with inst any nonlocals in negated
	contexts.

	Delete any_map.common_subset.  It shouldn't be a part of this library
	since it may unintentionally further constrain two solver types.

Julien.

Index: any_assoc_list.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/solver_types/library/any_assoc_list.m,v
retrieving revision 1.1
diff -u -r1.1 any_assoc_list.m
--- any_assoc_list.m	12 Sep 2005 02:17:48 -0000	1.1
+++ any_assoc_list.m	10 Nov 2005 02:20:52 -0000
@@ -89,7 +89,7 @@
 :- import_module string.

 any_assoc_list__from_corresponding_lists(Ks, Vs, KVs) :-
-    ( any_assoc_list__from_corresponding_2(Ks, Vs, KVs0) ->
+    ( impure any_assoc_list__from_corresponding_2(Ks, Vs, KVs0) ->
         KVs = KVs0
     ;
         KeyType = type_name(type_of(Ks)),
@@ -175,7 +175,7 @@
     any_assoc_list__search(AL, K, V).

 AL ^ det_elem(K) = V :-
-    ( if   any_assoc_list__search(AL, K, V0)
+    ( if   impure any_assoc_list__search(AL, K, V0)
       then V = V0
       else report_lookup_error("any_assoc_list__det_elem: key not found", K)
     ).
Index: any_list.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/solver_types/library/any_list.m,v
retrieving revision 1.1
diff -u -r1.1 any_list.m
--- any_list.m	12 Sep 2005 02:17:48 -0000	1.1
+++ any_list.m	10 Nov 2005 02:50:39 -0000
@@ -739,7 +739,7 @@
 %-----------------------------------------------------------------------------%

 index0_det(List, N) = Elem :-
-    ( index0(List, N, Elem0) ->
+    ( impure index0(List, N, Elem0) ->
         Elem = Elem0
     ;
         error("index: index out of range")
@@ -782,7 +782,7 @@

 replace_nth_det(Xs, P, R) = L :-
     ( P > 0 ->
-        ( replace_nth_2(Xs, P, R, L0) ->
+        ( impure replace_nth_2(Xs, P, R, L0) ->
             L = L0
         ;
             error("replace_nth_det: " ++
@@ -878,7 +878,7 @@
     ).

 take_upto(N, As) = Bs :-
-    ( take(N, As, Bs0) ->
+    ( impure take(N, As, Bs0) ->
         Bs = Bs0
     ;
         Bs = As
@@ -960,7 +960,7 @@
     ).

 det_last(List) = Last :-
-    ( last(List, LastPrime) ->
+    ( impure last(List, LastPrime) ->
         Last = LastPrime
     ;
         error("last_det: empty list")
@@ -978,7 +978,7 @@
     ).

 split_last_det(List, AllButLast, Last) :-
-    ( split_last(List, AllButLastPrime, LastPrime) ->
+    ( impure split_last(List, AllButLastPrime, LastPrime) ->
         AllButLast = AllButLastPrime,
         Last = LastPrime
     ;
Index: any_map.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/solver_types/library/any_map.m,v
retrieving revision 1.2
diff -u -r1.2 any_map.m
--- any_map.m	13 Sep 2005 08:35:39 -0000	1.2
+++ any_map.m	10 Nov 2005 02:42:55 -0000
@@ -467,23 +467,6 @@
 :- mode any_map__det_intersect(func(ia, ia) = oa is semidet, ia, ia) = oa
         is det.

-    % Given two maps M1 and M2, create a third map M3 that has only the
-    % keys that occur in both M1 and M2. For keys that occur in both M1
-    % and M2, compute the corresponding values. If they are the same,
-    % include the key/value pair in M3. If they differ, do not include the
-    % key in M3.
-    %
-    % This predicate effectively considers the input maps to be sets of
-    % key/value pairs, computes the intersection of those two sets, and
-    % returns the map corresponding to the intersection.
-    %
-    % any_map__common_subset is very similar to any_map__intersect, but can
-    % succeed even with an output map that does not contain an entry for a key
-    % value that occurs in both input maps.
-    %
-:- func any_map__common_subset(any_map(K, V)::ia, any_map(K, V)::ia)
-        = (any_map(K, V)::oa) is det.
-
     % Given two maps M1 and M2, create a third map M3 that all the keys
     % that occur in either M1 and M2. For keys that occur in both M1
     % and M2, compute the value in the final map by applying the supplied
@@ -570,7 +553,7 @@
     any_tree234__search(Map, K, V).

 any_map__lookup(Map, K, V) :-
-    ( any_tree234__search(Map, K, V1) ->
+    ( impure any_tree234__search(Map, K, V1) ->
         V = V1
     ;
         report_lookup_error("any_map__lookup: key not found", K, V)
@@ -580,7 +563,7 @@
     any_tree234__lower_bound_search(Map, SearchK, K, V).

 any_map__lower_bound_lookup(Map, SearchK, K, V) :-
-    ( any_tree234__lower_bound_search(Map, SearchK, K1, V1) ->
+    ( impure any_tree234__lower_bound_search(Map, SearchK, K1, V1) ->
         K = K1,
         V = V1
     ;
@@ -592,7 +575,7 @@
     any_tree234__upper_bound_search(Map, SearchK, K, V).

 any_map__upper_bound_lookup(Map, SearchK, K, V) :-
-    ( any_tree234__upper_bound_search(Map, SearchK, K1, V1) ->
+    ( impure any_tree234__upper_bound_search(Map, SearchK, K1, V1) ->
         K = K1,
         V = V1
     ;
@@ -608,7 +591,7 @@
     any_tree234__insert(Map0, K, V, Map).

 any_map__det_insert(Map0, K, V, Map) :-
-    ( any_tree234__insert(Map0, K, V, Map1) ->
+    ( impure any_tree234__insert(Map0, K, V, Map1) ->
         Map = Map1
     ;
         report_lookup_error("any_map__det_insert: key already present",
@@ -666,7 +649,7 @@
     any_tree234__update(Map0, K, V, Map).

 any_map__det_update(Map0, K, V, Map) :-
-    ( any_tree234__update(Map0, K, V, Map1) ->
+    ( impure any_tree234__update(Map0, K, V, Map1) ->
         Map = Map1
     ;
         report_lookup_error("any_map__det_update: key not found", K, V)
@@ -677,7 +660,7 @@

 any_map__det_transform_value(P, K, !Map) :-
     (
-        any_map__transform_value(P, K, !.Map, NewMap)
+        impure any_map__transform_value(P, K, !.Map, NewMap)
     ->
         !:Map = NewMap
     ;
@@ -727,7 +710,7 @@
     any_tree234__remove(Map0, Key, Value, Map).

 any_map__det_remove(Map0, Key, Value, Map) :-
-    ( any_tree234__remove(Map0, Key, Value1, Map1) ->
+    ( impure any_tree234__remove(Map0, Key, Value1, Map1) ->
         Value = Value1,
         Map = Map1
     ;
@@ -783,7 +766,7 @@
 any_map__overlay_large_map_2([], Map, Map).
 any_map__overlay_large_map_2([K - V | AssocList], Map0, Map) :-
     unsafe_cast_to_ground(K),
-    ( any_map__insert(Map0, K, V, Map1) ->
+    ( impure any_map__insert(Map0, K, V, Map1) ->
         Map2 = Map1
     ;
         Map2 = Map0
@@ -802,7 +785,7 @@

 any_map__select_2([], _Original, New, New).
 any_map__select_2([K|Ks], Original, New0, New) :-
-    ( any_map__search(Original, K, V) ->
+    ( impure any_map__search(Original, K, V) ->
         any_map__set(New0, K, V, New1)
     ;
         New1 = New0
@@ -895,7 +878,7 @@
     ).

 any_map__det_intersect(CommonPred, Map1, Map2, Common) :-
-    ( any_map__intersect(CommonPred, Map1, Map2, CommonPrime) ->
+    ( impure any_map__intersect(CommonPred, Map1, Map2, CommonPrime) ->
         Common = CommonPrime
     ;
         error("any_map__det_intersect: any_map__intersect failed")
@@ -903,57 +886,6 @@

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

-any_map__common_subset(Map1, Map2) = Common :-
-    any_map__to_sorted_any_assoc_list(Map1, AssocList1),
-    any_map__to_sorted_any_assoc_list(Map2, AssocList2),
-    any_map__init(Common0),
-    any_map__common_subset_2(AssocList1, AssocList2, Common0) = Common.
-
-:- func any_map__common_subset_2(any_assoc_list(K, V)::ia,
-        any_assoc_list(K, V)::ia, any_map(K, V)::ia) = (any_map(K, V)::oa)
-        is det.
-
-any_map__common_subset_2(AssocList1, AssocList2, Common0) = Common :-
-    (
-        AssocList1 = [],
-        AssocList2 = [],
-        Common = Common0
-    ;
-        AssocList1 = [_ | _],
-        AssocList2 = [],
-        Common = Common0
-    ;
-        AssocList1 = [],
-        AssocList2 = [_ | _],
-        Common = Common0
-    ;
-        AssocList1 = [Key1 - Value1 | AssocTail1],
-        AssocList2 = [Key2 - Value2 | AssocTail2],
-        unsafe_cast_to_ground(Key1),
-        unsafe_cast_to_ground(Key2),
-        compare(R, Key1, Key2),
-        (
-            R = (=),
-            ( Value1 = Value2 ->
-                any_map__det_insert(Common0, Key1, Value1, Common1)
-            ;
-                Common1 = Common0
-            ),
-            Common = any_map__common_subset_2(AssocTail1, AssocTail2,
-                Common1)
-        ;
-            R = (<),
-            Common = any_map__common_subset_2(AssocTail1, AssocList2,
-                Common0)
-        ;
-            R = (>),
-            Common = any_map__common_subset_2(AssocList1, AssocTail2,
-                Common0)
-        )
-    ).
-
-%-----------------------------------------------------------------------------%
-
 any_map__union(CommonPred, Map1, Map2, Common) :-
     any_map__to_sorted_any_assoc_list(Map1, AssocList1),
     any_map__to_sorted_any_assoc_list(Map2, AssocList2),
@@ -1006,7 +938,7 @@
     ).

 any_map__det_union(CommonPred, Map1, Map2, Union) :-
-    ( any_map__union(CommonPred, Map1, Map2, UnionPrime) ->
+    ( impure any_map__union(CommonPred, Map1, Map2, UnionPrime) ->
         Union = UnionPrime
     ;
         error("any_map__det_union: any_map__union failed")
Index: any_tree234.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/solver_types/library/any_tree234.m,v
retrieving revision 1.1
diff -u -r1.1 any_tree234.m
--- any_tree234.m	12 Sep 2005 02:17:49 -0000	1.1
+++ any_tree234.m	10 Nov 2005 02:49:12 -0000
@@ -391,7 +391,7 @@
     ).

 any_tree234__lookup(T, K, V) :-
-    ( any_tree234__search(T, K, V0) ->
+    ( impure any_tree234__search(T, K, V0) ->
         V = V0
     ;
         report_lookup_error("any_tree234__lookup: key not found.", K, V)
@@ -416,7 +416,7 @@
             V = V0
         ;
             Result = (>),
-            ( any_tree234__lower_bound_search(T1, SearchK, Kp, Vp) ->
+            ( impure any_tree234__lower_bound_search(T1, SearchK, Kp, Vp) ->
                 K = Kp,
                 V = Vp
             ;
@@ -442,7 +442,7 @@
             compare(Result1, SearchK, K1),
             (
                 Result1 = (<),
-                ( any_tree234__lower_bound_search(T1, SearchK,
+                ( impure any_tree234__lower_bound_search(T1, SearchK,
                     Kp, Vp)
                 ->
                     K = Kp,
@@ -458,7 +458,7 @@
                 V = V1
             ;
                 Result1 = (>),
-                ( any_tree234__lower_bound_search(T2, SearchK,
+                ( impure any_tree234__lower_bound_search(T2, SearchK,
                     Kp, Vp)
                 ->
                     K = Kp,
@@ -486,7 +486,7 @@
                 V = V0
             ;
                 Result0 = (>),
-                ( any_tree234__lower_bound_search(T1, SearchK,
+                ( impure any_tree234__lower_bound_search(T1, SearchK,
                     Kp, Vp)
                 ->
                     K = Kp,
@@ -506,7 +506,7 @@
             compare(Result2, SearchK, K2),
             (
                 Result2 = (<),
-                ( any_tree234__lower_bound_search(T2, SearchK,
+                ( impure any_tree234__lower_bound_search(T2, SearchK,
                     Kp, Vp)
                 ->
                     K = Kp,
@@ -521,7 +521,7 @@
                 V = V2
             ;
                 Result2 = (>),
-                ( any_tree234__lower_bound_search(T3, SearchK,
+                ( impure any_tree234__lower_bound_search(T3, SearchK,
                     Kp, Vp)
                 ->
                     K = Kp,
@@ -535,7 +535,7 @@
     ).

 any_tree234__lower_bound_lookup(T, SearchK, K, V) :-
-    ( any_tree234__lower_bound_search(T, SearchK, K0, V0) ->
+    ( impure any_tree234__lower_bound_search(T, SearchK, K0, V0) ->
         K = K0,
         V = V0
     ;
@@ -555,7 +555,7 @@
         compare(Result, SearchK, K0),
         (
             Result = (<),
-            ( any_tree234__upper_bound_search(T0, SearchK, Kp, Vp) ->
+            ( impure any_tree234__upper_bound_search(T0, SearchK, Kp, Vp) ->
                 K = Kp,
                 V = Vp
             ;
@@ -577,7 +577,7 @@
         compare(Result0, SearchK, K0),
         (
             Result0 = (<),
-            ( any_tree234__upper_bound_search(T0, SearchK, Kp, Vp) ->
+            ( impure any_tree234__upper_bound_search(T0, SearchK, Kp, Vp) ->
                 K = Kp,
                 V = Vp
             ;
@@ -594,7 +594,7 @@
             compare(Result1, SearchK, K1),
             (
                 Result1 = (<),
-                ( any_tree234__upper_bound_search(T1, SearchK,
+                ( impure any_tree234__upper_bound_search(T1, SearchK,
                     Kp, Vp)
                 ->
                     K = Kp,
@@ -622,7 +622,7 @@
             compare(Result0, SearchK, K0),
             (
                 Result0 = (<),
-                ( any_tree234__upper_bound_search(T0, SearchK,
+                ( impure any_tree234__upper_bound_search(T0, SearchK,
                     Kp, Vp)
                 ->
                     K = Kp,
@@ -637,7 +637,7 @@
                 V = V0
             ;
                 Result0 = (>),
-                ( any_tree234__upper_bound_search(T1, SearchK,
+                ( impure any_tree234__upper_bound_search(T1, SearchK,
                     Kp, Vp)
                 ->
                     K = Kp,
@@ -657,7 +657,7 @@
             compare(Result2, SearchK, K2),
             (
                 Result2 = (<),
-                ( any_tree234__upper_bound_search(T2, SearchK,
+                ( impure any_tree234__upper_bound_search(T2, SearchK,
                     Kp, Vp)
                 ->
                     K = Kp,
@@ -678,7 +678,7 @@
     ).

 any_tree234__upper_bound_lookup(T, SearchK, K, V) :-
-    ( any_tree234__upper_bound_search(T, SearchK, K0, V0) ->
+    ( impure any_tree234__upper_bound_search(T, SearchK, K0, V0) ->
         K = K0,
         V = V0
     ;
@@ -693,7 +693,7 @@
     ; T0 = three(_, _, NodeMaxKey, _, _, _, NodeMaxSubtree)
     ; T0 = four(_, _, _, _, NodeMaxKey, _, _, _, _, NodeMaxSubtree)
     ),
-    ( MaxSubtreeKey = any_tree234__max_key(NodeMaxSubtree) ->
+    ( impure MaxSubtreeKey = any_tree234__max_key(NodeMaxSubtree) ->
         MaxKey = MaxSubtreeKey
     ;
         MaxKey = NodeMaxKey
@@ -705,7 +705,7 @@
     ; T0 = three(NodeMinKey, _, _, _, NodeMinSubtree, _, _)
     ; T0 = four(NodeMinKey, _, _, _, _, _, NodeMinSubtree, _, _, _)
     ),
-    ( MinSubtreeKey = any_tree234__min_key(NodeMinSubtree) ->
+    ( impure MinSubtreeKey = any_tree234__min_key(NodeMinSubtree) ->
         MinKey = MinSubtreeKey
     ;
         MinKey = NodeMinKey
@@ -1589,7 +1589,7 @@
         ;
             Result0 = (=),
             (
-                any_tree234__remove_smallest_2(T1, ST1K, ST1V,
+                impure any_tree234__remove_smallest_2(T1, ST1K, ST1V,
                     NewT1, RHT1)
             ->
                 ( RHT1 = yes ->
@@ -1631,7 +1631,7 @@
         ;
             Result0 = (=),
             (
-                any_tree234__remove_smallest_2(T1, ST1K, ST1V,
+                impure any_tree234__remove_smallest_2(T1, ST1K, ST1V,
                     NewT1, RHT1)
             ->
                 ( RHT1 = yes ->
@@ -1665,7 +1665,7 @@
             ;
                 Result1 = (=),
                 (
-                    any_tree234__remove_smallest_2(T2,
+                    impure any_tree234__remove_smallest_2(T2,
                         ST2K, ST2V, NewT2, RHT2)
                 ->
                     ( RHT2 = yes ->
@@ -1716,7 +1716,7 @@
             ;
                 Result0 = (=),
                 (
-                    any_tree234__remove_smallest_2(T1,
+                    impure any_tree234__remove_smallest_2(T1,
                         ST1K, ST1V, NewT1, RHT1)
                 ->
                     ( RHT1 = yes ->
@@ -1751,7 +1751,7 @@
         ;
             Result1 = (=),
             (
-                any_tree234__remove_smallest_2(T2, ST2K, ST2V,
+                impure any_tree234__remove_smallest_2(T2, ST2K, ST2V,
                     NewT2, RHT2)
             ->
                 ( RHT2 = yes ->
@@ -1785,7 +1785,7 @@
             ;
                 Result2 = (=),
                 (
-                    any_tree234__remove_smallest_2(T3,
+                    impure any_tree234__remove_smallest_2(T3,
                         ST3K, ST3V, NewT3, RHT3)
                 ->
                     ( RHT3 = yes ->
@@ -1850,7 +1850,7 @@
         ;
             Result0 = (=),
             (
-                any_tree234__remove_smallest_2(T1, ST1K, ST1V,
+                impure any_tree234__remove_smallest_2(T1, ST1K, ST1V,
                     NewT1, RHT1)
             ->
                 ( RHT1 = yes ->
@@ -1893,7 +1893,7 @@
         ;
             Result0 = (=),
             (
-                any_tree234__remove_smallest_2(T1, ST1K, ST1V,
+                impure any_tree234__remove_smallest_2(T1, ST1K, ST1V,
                     NewT1, RHT1)
             ->
                 ( RHT1 = yes ->
@@ -1928,7 +1928,7 @@
             ;
                 Result1 = (=),
                 (
-                    any_tree234__remove_smallest_2(T2,
+                    impure any_tree234__remove_smallest_2(T2,
                         ST2K, ST2V, NewT2, RHT2)
                 ->
                     ( RHT2 = yes ->
@@ -1980,7 +1980,7 @@
             ;
                 Result0 = (=),
                 (
-                    any_tree234__remove_smallest_2(T1,
+                    impure any_tree234__remove_smallest_2(T1,
                         ST1K, ST1V, NewT1, RHT1)
                 ->
                     ( RHT1 = yes ->
@@ -2016,7 +2016,7 @@
         ;
             Result1 = (=),
             (
-                any_tree234__remove_smallest_2(T2, ST2K, ST2V,
+                impure any_tree234__remove_smallest_2(T2, ST2K, ST2V,
                     NewT2, RHT2)
             ->
                 ( RHT2 = yes ->
@@ -2051,7 +2051,7 @@
             ;
                 Result2 = (=),
                 (
-                    any_tree234__remove_smallest_2(T3,
+                    impure any_tree234__remove_smallest_2(T3,
                         ST3K, ST3V, NewT3, RHT3)
                 ->
                     ( RHT3 = yes ->

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