[m-rev.] diff: change predicate argument order in array module

Julien Fischer juliensf at csse.unimelb.edu.au
Sat May 7 01:18:30 AEST 2011


Branches: main

Change the order of predicate arguments in the array module to make them
more conducive to the use of state variable notation.

library/array.m:
 	As above.

 	Group clauses for functions with those of the corresponding
 	predicate.

library/svarray.m:
library/hash_table.m:
library/io.m:
library/random.m:
compiler/lambda.m:
deep_profiler/array_util.m:
deep_profiler/callgraph.m:
deep_profiler/canonical.m:
deep_profiler/cliques.m:
deep_profiler/dense_bitset.m:
deep_profiler/measurements.m:
deep_profiler/profile.m:
deep_profiler/read_profile.m:
deep_profiler/startup.m:
tests/general/array_test.m:
tests/general/mode_inf.m:
tests/hard_coded/array_test2.m:
tests/hard_coded/lp.m:
tests/hard_coded/reuse_array.m:
 	Conform to the above change and remove dependencies
 	on the svarray module.

tests/general/set_test.m:
 	Replace calls to set_bbbtree.size/2 with calls to
 	set_bbbtree.count/2.

NEWS:
 	Announce the above change.

Julien.

Index: NEWS
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/NEWS,v
retrieving revision 1.564
diff -u -r1.564 NEWS
--- NEWS	6 May 2011 05:03:18 -0000	1.564
+++ NEWS	6 May 2011 15:04:03 -0000
@@ -12,8 +12,8 @@

  * We have improved Unicode support in the standard library.

-* We have changed the argument order of many of the predicates in the
-  bag, bimap, eqvclass, map, multi_map, queue and set  modules in order
+* We have changed the argument order of many of the predicates in the array,
+  bag, bimap, eqvclass, map, multi_map, queue and set modules in order
    to make them more conducive to the use of state variable notation.


@@ -33,13 +33,15 @@

  * The argument order of the following predicates has been changed so as to
    make them more conducive to the use of state variable notation:
-  bag.insert/3, bag.insert_list/3, bag.insert_set/3. bag.remove/3,
-  bag.det_remove/3, bag.remove_list/3, bag.remove_set/3, bag.delete/3,
-  bag.remove_all/3, bag.delete_all/3, bag.remove_smallest/3,
-  bimap.insert/4, bimap.det_insert/4, bimap.set/4, eqvclass.ensure_element/3,
-  eqvclass.new_element/3, eqvclass.ensure_equivalence/4,
-  eqvclass.new_equivalence/4, eqvclass.remove_equivalent_elements/3,
-  map.insert/4, map.det_insert/4, map.det_insert_from_corresponding_lists/4,
+  array.set/4, array.semidet/4, array.slow_set/4, array.semidet_slow_set/4,
+  array.resize/4, array.shrink/3, bag.insert/3, bag.insert_list/3,
+  bag.insert_set/3, bag.remove/3, bag.det_remove/3, bag.remove_list/3,
+  bag.remove_set/3, bag.delete/3, bag.remove_all/3, bag.delete_all/3,
+  bag.remove_smallest/3, bimap.insert/4, bimap.det_insert/4, bimap.set/4,
+  eqvclass.ensure_element/3, eqvclass.new_element/3,
+  eqvclass.ensure_equivalence/4, eqvclass.new_equivalence/4,
+  eqvclass.remove_equivalent_elements/3, map.insert/4, map.det_insert/4,
+  map.det_insert_from_corresponding_lists/4,
    map.det_insert_from_assoc_list/3, map.set_from_corresponding_lists/4,
    map.set_from_assoc_list/3, map.update/4, map.det_update/4, map.delete/3,
    map.delete_list/3, map.remove/4, map.det_remove/4, map.remove_smallest/4,
@@ -50,7 +52,7 @@
    queue.get/3, queue.delete_all/3, queue.put_on_front/3,
    queue.get_from_back/3, queue.put_list_on_front/3,
    queue.get_from_back/3, set.insert/3, set.insert_list/3, set.delete/3,
-  set.delete_list/3, set.remove/3, set.remove_list/3 and  set.remove_least/3
+  set.delete_list/3, set.remove/3, set.remove_list/3 and set.remove_least/3

  * We have add the following new functions for creating singleton
    maps: bimap.singleton/2, injection.singleton/2, map.singleton/2,
Index: compiler/lambda.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/lambda.m,v
retrieving revision 1.149
diff -u -r1.149 lambda.m
--- compiler/lambda.m	6 May 2011 05:03:21 -0000	1.149
+++ compiler/lambda.m	6 May 2011 06:55:24 -0000
@@ -827,7 +827,7 @@
  :- pragma inline(mark_var_as_used/3).

  mark_var_as_used(Var, !VarUses) :-
-    array.set(!.VarUses, var_to_int(Var), yes, !:VarUses).
+    array.set(var_to_int(Var), yes, !VarUses).

  :- pred mark_vars_as_used(list(prog_var)::in,
      array(bool)::array_di, array(bool)::array_uo) is det.
Index: deep_profiler/array_util.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/deep_profiler/array_util.m,v
retrieving revision 1.13
diff -u -r1.13 array_util.m
--- deep_profiler/array_util.m	15 Dec 2010 06:30:32 -0000	1.13
+++ deep_profiler/array_util.m	6 May 2011 07:01:02 -0000
@@ -256,7 +256,7 @@
      ;
          array.lookup(!.Array, N, OldElem),
          Closure(OldElem, NewElem),
-        array.set(!.Array, N, NewElem, !:Array),
+        array.set(N, NewElem, !Array),
          array_map(N + 1, Size, Closure, !Array)
      ).

Index: deep_profiler/callgraph.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/deep_profiler/callgraph.m,v
retrieving revision 1.13
diff -u -r1.13 callgraph.m
--- deep_profiler/callgraph.m	15 Dec 2010 06:30:32 -0000	1.13
+++ deep_profiler/callgraph.m	6 May 2011 14:57:00 -0000
@@ -43,7 +43,6 @@
  :- import_module io.
  :- import_module set.
  :- import_module string.
-:- import_module svarray.

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

@@ -179,7 +178,7 @@
      trace [compiletime(flag("index_clique_member")), io(!IO)] (
          write_pdi_cn(PDI, CliqueNum, !IO)
      ),
-    svarray.set(PDI, clique_ptr(CliqueNum), !CliqueIndex).
+    array.set(PDI, clique_ptr(CliqueNum), !CliqueIndex).

  %-----------------------------------------------------------------------------%
  %
Index: deep_profiler/canonical.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/deep_profiler/canonical.m,v
retrieving revision 1.24
diff -u -r1.24 canonical.m
--- deep_profiler/canonical.m	6 May 2011 05:03:27 -0000	1.24
+++ deep_profiler/canonical.m	6 May 2011 14:57:21 -0000
@@ -41,7 +41,6 @@
  :- import_module require.
  :- import_module set.
  :- import_module string.
-:- import_module svarray.

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

@@ -273,18 +272,17 @@
      is det.

  merge_proc_dynamic_slots(MergeInfo, SlotNum, Clique, PrimePDPtr,
-        PrimeSiteArray0, RestSiteArrays, PrimeSiteArray,
+        !.PrimeSiteArray, RestSiteArrays, !:PrimeSiteArray,
          !InitDeep, !Redirect) :-
      ( SlotNum >= 0 ->
-        array.lookup(PrimeSiteArray0, SlotNum, PrimeSite0),
+        array.lookup(!.PrimeSiteArray, SlotNum, PrimeSite0),
          (
              PrimeSite0 = slot_normal(PrimeCSDPtr0),
              merge_proc_dynamic_normal_slot(MergeInfo, SlotNum,
                  Clique, PrimePDPtr, PrimeCSDPtr0,
                  RestSiteArrays, PrimeCSDPtr,
                  !InitDeep, !Redirect),
-            array.set(PrimeSiteArray0, SlotNum,
-                slot_normal(PrimeCSDPtr), PrimeSiteArray1)
+            array.set(SlotNum, slot_normal(PrimeCSDPtr), !PrimeSiteArray)
          ;
              PrimeSite0 = slot_multi(IsZeroed, PrimeCSDPtrArray0),
              array.to_list(PrimeCSDPtrArray0, PrimeCSDPtrList0),
@@ -293,15 +291,15 @@
                  RestSiteArrays, PrimeCSDPtrList,
                  !InitDeep, !Redirect),
              PrimeCSDPtrArray = array(PrimeCSDPtrList),
-            array.set(PrimeSiteArray0, SlotNum,
+            array.set(SlotNum,
                  slot_multi(IsZeroed, PrimeCSDPtrArray),
-                PrimeSiteArray1)
+                !PrimeSiteArray)
          ),
          merge_proc_dynamic_slots(MergeInfo, SlotNum - 1, Clique,
-            PrimePDPtr, PrimeSiteArray1, RestSiteArrays,
-            PrimeSiteArray, !InitDeep, !Redirect)
+            PrimePDPtr, !.PrimeSiteArray, RestSiteArrays,
+            !:PrimeSiteArray, !InitDeep, !Redirect)
      ;
-        PrimeSiteArray = PrimeSiteArray0
+        true
      ).

  :- pred merge_proc_dynamic_normal_slot(merge_info::in, int::in,
@@ -644,7 +642,7 @@

  set_pd_redirect(ProcRedirect0, PDPtr, NewRedirect, ProcRedirect) :-
      PDPtr = proc_dynamic_ptr(PDI),
-    array.set(ProcRedirect0, PDI, NewRedirect, ProcRedirect).
+    array.set(PDI, NewRedirect, ProcRedirect0, ProcRedirect).

  :- pred lookup_csd_redirect(array(call_site_dynamic_ptr)::in,
      call_site_dynamic_ptr::in, call_site_dynamic_ptr::out) is det.
@@ -659,7 +657,7 @@

  set_csd_redirect(CallSiteRedirect0, CSDPtr, NewRedirect, CallSiteRedirect) :-
      CSDPtr = call_site_dynamic_ptr(CSDI),
-    array.set(CallSiteRedirect0, CSDI, NewRedirect, CallSiteRedirect).
+    array.set(CSDI, NewRedirect, CallSiteRedirect0, CallSiteRedirect).

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

@@ -704,8 +702,8 @@
          u(CSDs0), CSDs1),
      array_map_from_1(subst_in_proc_dynamic(Redirect),
          u(PDs0), PDs1),
-    array.shrink(CSDs1, NumCSD, CSDs),
-    array.shrink(PDs1, NumPD, PDs),
+    array.shrink(NumCSD, CSDs1, CSDs),
+    array.shrink(NumPD, PDs1, PDs),
      lookup_pd_redirect(PDredirect, Root0, Root),
      !:InitDeep = initial_deep(Stats, Root, CSDs, PDs, CSSs, PSs).

@@ -719,7 +717,7 @@
      ;
          array.lookup(!.CSDredirect, CurOld, Redirect0),
          ( Redirect0 = call_site_dynamic_ptr(0) ->
-            svarray.set(CurOld, call_site_dynamic_ptr(CurNew), !CSDredirect),
+            array.set(CurOld, call_site_dynamic_ptr(CurNew), !CSDredirect),
              compact_csd_redirect(CurOld + 1, CurNew + 1, MaxOld, NumNew,
                  !CSDredirect)
          ;
@@ -740,7 +738,7 @@
      ;
          array.lookup(!.PDredirect, CurOld, Redirect0),
          ( Redirect0 = proc_dynamic_ptr(0) ->
-            svarray.set(CurOld, proc_dynamic_ptr(CurNew), !PDredirect),
+            array.set(CurOld, proc_dynamic_ptr(CurNew), !PDredirect),
              compact_pd_redirect(CurOld + 1, CurNew + 1, MaxOld, NumNew,
                  !PDredirect)
          ;
@@ -913,7 +911,7 @@
          concat_proc_dynamic_ptr(PrevMaxPD, CallerPDPtr0, CallerPDPtr),
          concat_proc_dynamic_ptr(PrevMaxPD, CalleePDPtr0, CalleePDPtr),
          CSD = call_site_dynamic(CallerPDPtr, CalleePDPtr, Own),
-        svarray.set(PrevMaxCSD + Cur, CSD, !ConcatCallSiteDynamics),
+        array.set(PrevMaxCSD + Cur, CSD, !ConcatCallSiteDynamics),
          concatenate_profile_csds(Cur + 1, Max, PrevMaxCSD, PrevMaxPD,
              CallSiteDynamics, !ConcatCallSiteDynamics)
      ;
@@ -933,7 +931,7 @@
          concatenate_profile_slots(0, MaxSite, PrevMaxCSD, PrevMaxPD,
              u(Sites0), Sites),
          PD = proc_dynamic(PSPtr, Sites, MaybeCPs),
-        svarray.set(PrevMaxPD + Cur, PD, !ConcatProcDynamics),
+        array.set(PrevMaxPD + Cur, PD, !ConcatProcDynamics),
          concatenate_profile_pds(Cur + 1, Max, PrevMaxCSD, PrevMaxPD,
              ProcDynamics, !ConcatProcDynamics)
      ;
@@ -957,7 +955,7 @@
                  u(CSDPtrs0), CSDPtrs),
              Slot = slot_multi(IsZeroed, CSDPtrs)
          ),
-        svarray.set(Cur, Slot, !Sites),
+        array.set(Cur, Slot, !Sites),
          concatenate_profile_slots(Cur + 1, Max, PrevMaxCSD, PrevMaxPD, !Sites)
      ;
          true
Index: deep_profiler/cliques.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/deep_profiler/cliques.m,v
retrieving revision 1.12
diff -u -r1.12 cliques.m
--- deep_profiler/cliques.m	6 May 2011 05:03:27 -0000	1.12
+++ deep_profiler/cliques.m	6 May 2011 07:04:43 -0000
@@ -73,12 +73,12 @@
      ( array.in_bounds(Array0, From) ->
          array.lookup(Array0, From, Tos0),
          set.insert(To, Tos0, Tos),
-        array.set(u(Array0), From, Tos, Array),
+        array.set(From, Tos, u(Array0), Array),
          Size = int.max(int.max(From, To), Size0),
          Graph = graph(Size, Array)
      ;
          array.size(Array0, Size),
-        array.resize(u(Array0), Size * 2, init, Array1),
+        array.resize(Size * 2, init, u(Array0), Array1),
          add_arc(graph(Size0, Array1), From, To, Graph)
      ).

Index: deep_profiler/dense_bitset.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/deep_profiler/dense_bitset.m,v
retrieving revision 1.7
diff -u -r1.7 dense_bitset.m
--- deep_profiler/dense_bitset.m	15 Dec 2010 06:30:33 -0000	1.7
+++ deep_profiler/dense_bitset.m	6 May 2011 07:05:28 -0000
@@ -80,12 +80,12 @@
  insert(A0, I) = A :-
      max(A0, Max),
      ( word(I) > Max ->
-        resize(A0, (Max + 1) * 2, 0, A1),
+        resize((Max + 1) * 2, 0, A0, A1),
          A = insert(A1, I)
      ; I >= 0 ->
          lookup(A0, word(I), Word0),
          Word = Word0 \/ bit(I),
-        set(A0, word(I), Word, A)
+        set(word(I), Word, A0, A)
      ;
          unexpected($module, $pred, "cannot use indexes < 0")
      ).
@@ -97,7 +97,7 @@
      ; I >= 0 ->
          lookup(A0, word(I), Word0),
          Word = Word0 /\ \ bit(I),
-        set(A0, word(I), Word, A)
+        set(word(I), Word, A0, A)
      ;
          unexpected($module, $pred, "cannot use indexes < 0")
      ).
Index: deep_profiler/measurements.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/deep_profiler/measurements.m,v
retrieving revision 1.29
diff -u -r1.29 measurements.m
--- deep_profiler/measurements.m	27 Jan 2011 08:03:53 -0000	1.29
+++ deep_profiler/measurements.m	6 May 2011 07:05:53 -0000
@@ -925,7 +925,7 @@
          array_foldl_from_0(
              (pred(Index::in, E::in, A0::array_di, A::array_uo) is det :-
                  lookup(A0, Index, Value),
-                set(A0, Index, Value + E, A)
+                set(Index, Value + E, A0, A)
              ), NewArray, !Array)
      ;
          unexpected($module, $pred, "arrays' bounds do not match")
Index: deep_profiler/profile.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/deep_profiler/profile.m,v
retrieving revision 1.35
diff -u -r1.35 profile.m
--- deep_profiler/profile.m	13 Jan 2011 00:36:55 -0000	1.35
+++ deep_profiler/profile.m	6 May 2011 07:12:30 -0000
@@ -906,77 +906,76 @@

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

-update_call_site_dynamics(CSDPtr, CSD, CallSiteDynamics0, CallSiteDynamics) :-
+update_call_site_dynamics(CSDPtr, CSD, !CallSiteDynamics) :-
      CSDPtr = call_site_dynamic_ptr(CSDI),
-    array.set(CallSiteDynamics0, CSDI, CSD, CallSiteDynamics).
+    array.set(CSDI, CSD, !CallSiteDynamics).

-update_call_site_statics(CSSPtr, CSS, CallSiteStatics0, CallSiteStatics) :-
+update_call_site_statics(CSSPtr, CSS, !CallSiteStatics) :-
      CSSPtr = call_site_static_ptr(CSSI),
-    array.set(CallSiteStatics0, CSSI, CSS, CallSiteStatics).
+    array.set(CSSI, CSS, !CallSiteStatics).

-update_proc_dynamics(PDPtr, PD, ProcDynamics0, ProcDynamics) :-
+update_proc_dynamics(PDPtr, PD, !ProcDynamics) :-
      PDPtr = proc_dynamic_ptr(PDI),
-    array.set(ProcDynamics0, PDI, PD, ProcDynamics).
+    array.set(PDI, PD, !ProcDynamics).

-update_proc_statics(PSPtr, PS, ProcStatics0, ProcStatics) :-
+update_proc_statics(PSPtr, PS, !ProcStatics) :-
      PSPtr = proc_static_ptr(PSI),
-    array.set(ProcStatics0, PSI, PS, ProcStatics).
+    array.set(PSI, PS, !ProcStatics).

-update_call_site_static_map(CSDPtr, CSSPtr,
-        CallSiteStaticMap0, CallSiteStaticMap) :-
+update_call_site_static_map(CSDPtr, CSSPtr, !CallSiteStaticMap) :-
      CSDPtr = call_site_dynamic_ptr(CSDI),
-    array.set(CallSiteStaticMap0, CSDI, CSSPtr, CallSiteStaticMap).
+    array.set(CSDI, CSSPtr, !CallSiteStaticMap).

-update_proc_callers(PSPtr, CSDPtrs, ProcCallers0, ProcCallers) :-
+update_proc_callers(PSPtr, CSDPtrs, !ProcCallers) :-
      PSPtr = proc_static_ptr(PSI),
-    array.set(ProcCallers0, PSI, CSDPtrs, ProcCallers).
+    array.set(PSI, CSDPtrs, !ProcCallers).

-update_ps_own(PSPtr, Own, PSOwns0, PSOwns) :-
+update_ps_own(PSPtr, Own, !PSOwns) :-
      PSPtr = proc_static_ptr(PSI),
-    array.set(PSOwns0, PSI, Own, PSOwns).
+    array.set(PSI, Own, !PSOwns).

-update_ps_desc(PSPtr, Desc, PSDescs0, PSDescs) :-
+update_ps_desc(PSPtr, Desc, !PSDescs) :-
      PSPtr = proc_static_ptr(PSI),
-    array.set(PSDescs0, PSI, Desc, PSDescs).
+    array.set(PSI, Desc, !PSDescs).

-update_css_own(CSSPtr, Own, CSSOwns0, CSSOwns) :-
+update_css_own(CSSPtr, Own, !CSSOwns) :-
      CSSPtr = call_site_static_ptr(CSSI),
-    array.set(CSSOwns0, CSSI, Own, CSSOwns).
+    array.set(CSSI, Own, !CSSOwns).

-update_css_desc(CSSPtr, Desc, CSSDescs0, CSSDescs) :-
+update_css_desc(CSSPtr, Desc, !CSSDescs) :-
      CSSPtr = call_site_static_ptr(CSSI),
-    array.set(CSSDescs0, CSSI, Desc, CSSDescs).
+    array.set(CSSI, Desc, !CSSDescs).

  update_ps_coverage(PSPtr, Coverage, !Coverages) :-
      PSPtr = proc_static_ptr(PSI),
-    array.set(!.Coverages, PSI, Coverage, !:Coverages).
+    array.set(PSI, Coverage, !Coverages).

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

-deep_update_csd_desc(CSDPtr, CSDDesc, Deep0, Deep) :-
+deep_update_csd_desc(CSDPtr, CSDDesc, !Deep) :-
      CSDPtr = call_site_dynamic_ptr(CSDI),
-    array.set(u(Deep0 ^ csd_desc), CSDI, CSDDesc, CSDDescs),
-    Deep = Deep0 ^ csd_desc := CSDDescs.
+    array.set(CSDI, CSDDesc, u(!.Deep ^ csd_desc), CSDDescs),
+    !Deep ^ csd_desc := CSDDescs.

-deep_update_pd_desc(PDPtr, PDDesc, Deep0, Deep) :-
+deep_update_pd_desc(PDPtr, PDDesc, !Deep) :-
      PDPtr = proc_dynamic_ptr(PDI),
-    array.set(u(Deep0 ^ pd_desc), PDI, PDDesc, PDDescs),
-    Deep = Deep0 ^ pd_desc := PDDescs.
+    array.set(PDI, PDDesc, u(!.Deep ^ pd_desc), PDDescs),
+    !Deep ^ pd_desc := PDDescs.

-deep_update_pd_own(PDPtr, PDOwn, Deep0, Deep) :-
+deep_update_pd_own(PDPtr, PDOwn, !Deep) :-
      PDPtr = proc_dynamic_ptr(PDI),
-    array.set(u(Deep0 ^ pd_own), PDI, PDOwn, PDOwns),
-    Deep = Deep0 ^ pd_own := PDOwns.
+    array.set(PDI, PDOwn, u(!.Deep ^ pd_own), PDOwns),
+    !Deep ^ pd_own := PDOwns.

-deep_update_pd_comp_table(PDPtr, CompTable, Deep0, Deep) :-
+deep_update_pd_comp_table(PDPtr, CompTable, !Deep) :-
      PDPtr = proc_dynamic_ptr(PDI),
-    array.set(u(Deep0 ^ pd_comp_table), PDI, CompTable, PDCompTables),
-    Deep = Deep0 ^ pd_comp_table := PDCompTables.
+    array.set(PDI, CompTable, u(!.Deep ^ pd_comp_table), PDCompTables),
+    !Deep ^ pd_comp_table := PDCompTables.

-deep_update_csd_comp_table(CSDPtr, CompTable, Deep0, Deep) :-
+deep_update_csd_comp_table(CSDPtr, CompTable, !Deep) :-
      CSDPtr = call_site_dynamic_ptr(CSDI),
-    array.set(u(Deep0 ^ csd_comp_table), CSDI, CompTable, CSDCompTables),
-    Deep = Deep0 ^ csd_comp_table := CSDCompTables.
+    array.set(CSDI, CompTable, u(!.Deep ^ csd_comp_table), CSDCompTables),
+    !Deep ^ csd_comp_table := CSDCompTables.

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

Index: deep_profiler/read_profile.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/deep_profiler/read_profile.m,v
retrieving revision 1.36
diff -u -r1.36 read_profile.m
--- deep_profiler/read_profile.m	7 Mar 2011 03:59:33 -0000	1.36
+++ deep_profiler/read_profile.m	6 May 2011 07:12:50 -0000
@@ -1496,7 +1496,7 @@
          % array.resize(u(A0), 2 * (Max + 1), X, A1),
          % deep_insert(A1, Ind, Item, A)
      ;
-        set(u(A0), Ind, Item, A)
+        set(Ind, Item, u(A0), A)
      ).

  %------------------------------------------------------------------------------%
Index: deep_profiler/startup.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/deep_profiler/startup.m,v
retrieving revision 1.28
diff -u -r1.28 startup.m
--- deep_profiler/startup.m	3 May 2011 04:35:00 -0000	1.28
+++ deep_profiler/startup.m	6 May 2011 14:57:39 -0000
@@ -57,7 +57,6 @@
  :- import_module map.
  :- import_module require.
  :- import_module string.
-:- import_module svarray.

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

@@ -536,8 +535,8 @@
              array.lookup(CliqueIndex, ChildPDI, ChildCliquePtr),
              ( ChildCliquePtr \= ParentCliquePtr ->
                  ChildCliquePtr = clique_ptr(ChildCliqueNum),
-                svarray.set(ChildCliqueNum, CSDPtr, !CliqueParents),
-                svarray.set(CSDI, yes(ChildCliquePtr), !CliqueMaybeChildren)
+                array.set(ChildCliqueNum, CSDPtr, !CliqueParents),
+                array.set(CSDI, yes(ChildCliquePtr), !CliqueMaybeChildren)
              ;
                  true
              )
@@ -693,7 +692,7 @@
              CallList = [CSDPtr],
              map.det_insert(PSPtr, CallList, CallMap0, CallMap)
          ),
-        svarray.set(CSSI, CallMap, !CallSiteCalls)
+        array.set(CSSI, CallMap, !CallSiteCalls)
      ;
          true
      ).
@@ -710,7 +709,7 @@
      ( PDI > 0 ->
          array.lookup(!.PDOwnArray, PDI, ProcOwn0),
          ProcOwn = add_own_to_own(CalleeOwn, ProcOwn0),
-        svarray.set(PDI, ProcOwn, !PDOwnArray)
+        array.set(PDI, ProcOwn, !PDOwnArray)
      ;
          error("sum_call_sites_in_proc_dynamic: invalid pdptr")
      ).
@@ -890,7 +889,7 @@
      (
          MaybeCoverage = yes(Coverage0),
          array_to_static_coverage(Coverage0, Coverage),
-        array.set(!.CoverageArray, Index, Coverage, !:CoverageArray)
+        array.set(Index, Coverage, !CoverageArray)
      ;
          MaybeCoverage = no,
          unexpected($module, $pred, "no coverage data in proc static")
Index: library/array.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/array.m,v
retrieving revision 1.182
diff -u -r1.182 array.m
--- library/array.m	3 May 2011 04:31:19 -0000	1.182
+++ library/array.m	6 May 2011 14:42:04 -0000
@@ -209,8 +209,8 @@
      % resulting array (good opportunity for destructive update ;-).
      % Throws an exception if the index is out of bounds.
      %
-:- pred array.set(array(T), int, T, array(T)).
-:- mode array.set(array_di, in, in, array_uo) is det.
+:- pred array.set(int, T, array(T), array(T)).
+:- mode array.set(in, in, array_di, array_uo) is det.

      % The same as array.set, except the arguments are in an order
      % that allows the use of state variables.
@@ -224,14 +224,14 @@
      % array.semidet_set sets the nth element of an array, and returns
      % the resulting array. It fails if the index is out of bounds.
      %
-:- pred array.semidet_set(array(T), int, T, array(T)).
-:- mode array.semidet_set(array_di, in, in, array_uo) is semidet.
+:- pred array.semidet_set(int, T, array(T), array(T)).
+:- mode array.semidet_set(in, in, array_di, array_uo) is semidet.

      % array.unsafe_set sets the nth element of an array, and returns the
      % resulting array.  It is an error if the index is out of bounds.
      %
-:- pred array.unsafe_set(array(T), int, T, array(T)).
-:- mode array.unsafe_set(array_di, in, in, array_uo) is det.
+:- pred array.unsafe_set(int, T, array(T), array(T)).
+:- mode array.unsafe_set(in, in, array_di, array_uo) is det.

      % The same as array.unsafe_set, except the arguments are in an order
      % that allows the use of state variables.
@@ -244,8 +244,8 @@
      % so the implementation may not be able to use destructive update.
      % It is an error if the index is out of bounds.
      %
-:- pred array.slow_set(array(T), int, T, array(T)).
-%:- mode array.slow_set(array_ui, in, in, array_uo) is det.
+:- pred array.slow_set(int, T, array(T), array(T)).
+%:- mode array.slow_set(in, in, array_ui, array_uo) is det.
  :- mode array.slow_set(in, in, in, array_uo) is det.

  :- func array.slow_set(array(T), int, T) = array(T).
@@ -257,8 +257,8 @@
      % so the implementation may not be able to use destructive update.
      % It fails if the index is out of bounds.
      %
-:- pred array.semidet_slow_set(array(T), int, T, array(T)).
-%:- mode array.semidet_slow_set(array_ui, in, in, array_uo) is semidet.
+:- pred array.semidet_slow_set(int, T, array(T), array(T)).
+%:- mode array.semidet_slow_set(in, in, array_ui, array_uo) is semidet.
  :- mode array.semidet_slow_set(in, in, in, array_uo) is semidet.

      % Field selection for arrays.
@@ -301,8 +301,8 @@
      % The array is expanded or shrunk to make it fit the new size `Size'.
      % Any new entries are filled with `Init'.
      %
-:- pred array.resize(array(T), int, T, array(T)).
-:- mode array.resize(array_di, in, in, array_uo) is det.
+:- pred array.resize(int, T, array(T), array(T)).
+:- mode array.resize(in, in, array_di, array_uo) is det.

  :- func array.resize(array(T), int, T) = array(T).
  :- mode array.resize(array_di, in, in) = array_uo is det.
@@ -311,8 +311,8 @@
      % The array is shrunk to make it fit the new size `Size'.
      % Throws an exception if `Size' is larger than the size of `Array0'.
      %
-:- pred array.shrink(array(T), int, array(T)).
-:- mode array.shrink(array_di, in, array_uo) is det.
+:- pred array.shrink(int, array(T), array(T)).
+:- mode array.shrink(in, array_di, array_uo) is det.

  :- func array.shrink(array(T), int) = array(T).
  :- mode array.shrink(array_di, in) = array_uo is det.
@@ -626,6 +626,9 @@
          array.equal_elements(N1, Size, Array1, Array2)
      ).

+array_compare(A1, A2) = C :-
+    array_compare(C, A1, A2).
+
      % compare/3 for arrays
      %
  :- pred array_compare(comparison_result::uo, array(T)::in, array(T)::in)
@@ -977,6 +980,9 @@
  }
  ").

+array.init(N, X) = A :-
+    array.init(N, X, A).
+
  array.init(Size, Item, Array) :-
      ( Size < 0 ->
          error("array.init: negative size")
@@ -999,6 +1005,9 @@
      ML_init_array(Array, Size, Item);
  ").

+array.make_empty_array = A :-
+    array.make_empty_array(A).
+
  :- pragma foreign_proc("C",
      array.make_empty_array(Array::array_uo),
      [will_not_call_mercury, promise_pure, thread_safe, will_not_modify_trail,
@@ -1057,6 +1066,9 @@

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

+array.min(A) = N :-
+    array.min(A, N).
+
  :- pragma foreign_proc("C",
      array.min(Array::in, Min::out),
      [will_not_call_mercury, promise_pure, thread_safe, will_not_modify_trail,
@@ -1090,6 +1102,9 @@
      Min = 0;
  ").

+array.max(A) = N :-
+    array.max(A, N).
+
  :- pragma foreign_proc("C",
      array.max(Array::in, Max::out),
      [will_not_call_mercury, promise_pure, thread_safe, will_not_modify_trail,
@@ -1131,6 +1146,9 @@

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

+array.size(A) = N :-
+    array.size(A, N).
+
  :- pragma foreign_proc("C",
      array.size(Array::in, Max::out),
      [will_not_call_mercury, promise_pure, thread_safe, will_not_modify_trail,
@@ -1170,33 +1188,37 @@
      array.bounds(Array, Min, Max),
      Min =< Index, Index =< Max.

-array.semidet_lookup(Array, Index, Item) :-
-    ( array.in_bounds(Array, Index) ->
-        array.unsafe_lookup(Array, Index, Item)
+array.semidet_set(Index, Item, !Array) :-
+    ( array.in_bounds(!.Array, Index) ->
+        array.unsafe_set(Index, Item, !Array)
      ;
          fail
      ).

-array.semidet_set(Array0, Index, Item, Array) :-
-    ( array.in_bounds(Array0, Index) ->
-        array.unsafe_set(Array0, Index, Item, Array)
+array.semidet_slow_set(Index, Item, !Array) :-
+    ( array.in_bounds(!.Array, Index) ->
+        array.slow_set(Index, Item, !Array)
      ;
          fail
      ).

-array.semidet_slow_set(Array0, Index, Item, Array) :-
-    ( array.in_bounds(Array0, Index) ->
-        array.slow_set(Array0, Index, Item, Array)
-    ;
-        fail
-    ).
+array.slow_set(!.Array, N, X) = !:Array :-
+    array.slow_set(N, X, !Array).

-array.slow_set(Array0, Index, Item, Array) :-
-    array.copy(Array0, Array1),
-    array.set(Array1, Index, Item, Array).
+array.slow_set(Index, Item, !Array) :-
+    array.copy(!Array),
+    array.set(Index, Item, !Array).

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

+array.elem(Index, Array) = array.lookup(Array, Index).
+
+array.unsafe_elem(Index, Array) = Elem :-
+    array.unsafe_lookup(Array, Index, Elem).
+
+array.lookup(Array, N) = X :-
+    array.lookup(Array, N, X).
+
  array.lookup(Array, Index, Item) :-
      ( bounds_checks, \+ array.in_bounds(Array, Index) ->
          out_of_bounds_error(Array, Index, "array.lookup")
@@ -1204,6 +1226,13 @@
          array.unsafe_lookup(Array, Index, Item)
      ).

+array.semidet_lookup(Array, Index, Item) :-
+    ( array.in_bounds(Array, Index) ->
+        array.unsafe_lookup(Array, Index, Item)
+    ;
+        fail
+    ).
+
  :- pragma foreign_proc("C",
      array.unsafe_lookup(Array::in, Index::in, Item::out),
      [will_not_call_mercury, promise_pure, thread_safe, will_not_modify_trail,
@@ -1249,25 +1278,30 @@

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

-array.set(Array0, Index, Item, Array) :-
-    ( bounds_checks, \+ array.in_bounds(Array0, Index) ->
-        out_of_bounds_error(Array0, Index, "array.set")
+'elem :='(Index, Array, Value) = array.set(Array, Index, Value).
+
+array.set(A1, N, X) = A2 :-
+    array.set(N, X, A1, A2).
+
+array.set(Index, Item, !Array) :-
+    ( bounds_checks, \+ array.in_bounds(!.Array, Index) ->
+        out_of_bounds_error(!.Array, Index, "array.set")
      ;
-        array.unsafe_set(Array0, Index, Item, Array)
+        array.unsafe_set(Index, Item, !Array)
      ).

-array.svset(Index, Item, Array0, Array) :-
-    ( bounds_checks, \+ array.in_bounds(Array0, Index) ->
-        out_of_bounds_error(Array0, Index, "array.set")
+array.svset(Index, Item, !Array) :-
+    ( bounds_checks, \+ array.in_bounds(!.Array, Index) ->
+        out_of_bounds_error(!.Array, Index, "array.set")
      ;
-        array.unsafe_svset(Index, Item, Array0, Array)
+        array.unsafe_svset(Index, Item, !Array)
      ).

  :- pragma foreign_proc("C",
-    array.unsafe_set(Array0::array_di, Index::in, Item::in, Array::array_uo),
+    array.unsafe_set(Index::in, Item::in, Array0::array_di, Array::array_uo),
      [will_not_call_mercury, promise_pure, thread_safe, will_not_modify_trail,
          does_not_affect_liveness,
-        sharing(yes(array(T), int, T, array(T)), [
+        sharing(yes(int, T, array(T), array(T)), [
              cel(Array0, []) - cel(Array, []),
              cel(Item, [])   - cel(Array, [T])
          ])
@@ -1367,7 +1401,8 @@
  % :- mode array.resize(in, in, in, out) is det.

  :- pragma foreign_decl("C", "
-void ML_resize_array(MR_ArrayPtr new_array, MR_ArrayPtr old_array,
+extern void
+ML_resize_array(MR_ArrayPtr new_array, MR_ArrayPtr old_array,
      MR_Integer array_size, MR_Word item);
  ").

@@ -1408,11 +1443,14 @@
  }
  ").

+array.resize(!.Array, N, X) = !:Array :-
+    array.resize(N, X, !Array).
+
  :- pragma foreign_proc("C",
-    array.resize(Array0::array_di, Size::in, Item::in, Array::array_uo),
+    array.resize(Size::in, Item::in, Array0::array_di, Array::array_uo),
      [will_not_call_mercury, promise_pure, thread_safe, will_not_modify_trail,
          does_not_affect_liveness,
-        sharing(yes(array(T), int, T, array(T)), [
+        sharing(yes(int, T, array(T), array(T)), [
              cel(Array0, []) - cel(Array, []),
              cel(Item, [])   - cel(Array, [T])
          ])
@@ -1460,7 +1498,8 @@
  %-----------------------------------------------------------------------------%

  :- pragma foreign_decl("C", "
-void ML_shrink_array(MR_ArrayPtr array, MR_ArrayPtr old_array,
+extern void
+ML_shrink_array(MR_ArrayPtr array, MR_ArrayPtr old_array,
      MR_Integer array_size);
  ").

@@ -1491,24 +1530,27 @@
  }
  ").

-array.shrink(Array0, Size, Array) :-
-    OldSize = array.size(Array0),
+array.shrink(!.Array, N) = !:Array :-
+    array.shrink(N, !Array).
+
+array.shrink(Size, !Array) :-
+    OldSize = array.size(!.Array),
      ( Size > OldSize ->
          error("array.shrink: can't shrink to a larger size")
      ; Size = OldSize ->
-        Array = Array0
+        true
      ;
-        array.shrink_2(Array0, Size, Array)
+        array.shrink_2(Size, !Array)
      ).

-:- pred array.shrink_2(array(T)::array_di, int::in, array(T)::array_uo)
+:- pred array.shrink_2(int::in, array(T)::array_di, array(T)::array_uo)
      is det.

  :- pragma foreign_proc("C",
-    array.shrink_2(Array0::array_di, Size::in, Array::array_uo),
+    array.shrink_2(Size::in, Array0::array_di, Array::array_uo),
      [will_not_call_mercury, promise_pure, thread_safe, will_not_modify_trail,
          does_not_affect_liveness,
-        sharing(yes(array(T), int, array(T)), [
+        sharing(yes(int, array(T), array(T)), [
              cel(Array0, []) - cel(Array, [])
          ])
      ],
@@ -1557,7 +1599,8 @@
  %-----------------------------------------------------------------------------%

  :- pragma foreign_decl("C", "
-void ML_copy_array(MR_ArrayPtr array, MR_ConstArrayPtr old_array);
+extern void
+ML_copy_array(MR_ArrayPtr array, MR_ConstArrayPtr old_array);
  ").

  :- pragma foreign_code("C", "
@@ -1585,6 +1628,9 @@
  }
  ").

+array.copy(A1) = A2 :-
+    array.copy(A1, A2).
+
  :- pragma foreign_proc("C",
      array.copy(Array0::in, Array::array_uo),
      [will_not_call_mercury, promise_pure, thread_safe, will_not_modify_trail,
@@ -1648,6 +1694,9 @@
  array(List) = Array :-
      array.from_list(List, Array).

+array.from_list(List) = Array :-
+    array.from_list(List, Array).
+
  array.from_list([], Array) :-
      array.make_empty_array(Array).
  array.from_list(List, Array) :-
@@ -1661,19 +1710,25 @@
  :- pred array.unsafe_insert_items(list(T)::in, int::in,
      array(T)::array_di, array(T)::array_uo) is det.

-array.unsafe_insert_items([], _N, Array, Array).
-array.unsafe_insert_items([Head|Tail], N, Array0, Array) :-
-    array.unsafe_set(Array0, N, Head, Array1),
-    array.unsafe_insert_items(Tail, N + 1, Array1, Array).
+array.unsafe_insert_items([], _N, !Array).
+array.unsafe_insert_items([Head | Tail], N, !Array) :-
+    array.unsafe_set(N, Head, !Array),
+    array.unsafe_insert_items(Tail, N + 1, !Array).

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

+array.to_list(Array) = List :-
+    array.to_list(Array, List).
+
  array.to_list(Array, List) :-
      array.bounds(Array, Low, High),
      array.fetch_items(Array, Low, High, List).

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

+array.fetch_items(Array, Low, High) = List :-
+    array.fetch_items(Array, Low, High, List).
+
  array.fetch_items(Array, Low, High, List) :-
      ( High < Low ->
          % If High is less than Low then there cannot be any array indexes
@@ -1692,6 +1747,10 @@

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

+array.bsearch(A, X, F) = MN :-
+    P = (pred(X1::in, X2::in, C::out) is det :- C = F(X1, X2)),
+    array.bsearch(A, X, P, MN).
+
  array.bsearch(A, El, Compare, Result) :-
      array.bounds(A, Lo, Hi),
      array.bsearch_2(A, Lo, Hi, El, Compare, Result).
@@ -1739,6 +1798,10 @@

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

+array.map(F, A1) = A2 :-
+    P = (pred(X::in, Y::out) is det :- Y = F(X)),
+    array.map(P, A1, A2).
+
  array.map(Closure, OldArray, NewArray) :-
      ( array.semidet_lookup(OldArray, 0, Elem0) ->
          array.size(OldArray, Size),
@@ -1752,87 +1815,23 @@
  :- pred array.map_2(int::in, int::in, pred(T1, T2)::in(pred(in, out) is det),
      array(T1)::in, array(T2)::array_di, array(T2)::array_uo) is det.

-array.map_2(N, Size, Closure, OldArray, NewArray0, NewArray) :-
+array.map_2(N, Size, Closure, OldArray, !NewArray) :-
      ( N >= Size ->
-        NewArray = NewArray0
+        true
      ;
          array.lookup(OldArray, N, OldElem),
          Closure(OldElem, NewElem),
-        array.set(NewArray0, N, NewElem, NewArray1),
-        array.map_2(N + 1, Size, Closure, OldArray,
-        NewArray1, NewArray)
+        array.set(N, NewElem, !NewArray),
+        array.map_2(N + 1, Size, Closure, OldArray, !NewArray)
      ).

  %-----------------------------------------------------------------------------%
-%-----------------------------------------------------------------------------%
-% Ralph Becket <rwab1 at cam.sri.com> 24/04/99
-%   Function forms added.
-
-array.make_empty_array = A :-
-    array.make_empty_array(A).
-
-array.init(N, X) = A :-
-    array.init(N, X, A).
-
-array.min(A) = N :-
-    array.min(A, N).
-
-array.max(A) = N :-
-    array.max(A, N).
-
-array.size(A) = N :-
-    array.size(A, N).
-
-array.lookup(A, N) = X :-
-    array.lookup(A, N, X).
-
-array.set(A1, N, X) = A2 :-
-    array.set(A1, N, X, A2).

-array.slow_set(A1, N, X) = A2 :-
-    array.slow_set(A1, N, X, A2).
-
-array.copy(A1) = A2 :-
-    array.copy(A1, A2).
-
-array.resize(A1, N, X) = A2 :-
-    array.resize(A1, N, X, A2).
-
-array.shrink(A1, N) = A2 :-
-    array.shrink(A1, N, A2).
-
-array.from_list(Xs) = A :-
-    array.from_list(Xs, A).
-
-array.to_list(A) = Xs :-
-    array.to_list(A, Xs).
-
-array.fetch_items(A, N1, N2) = Xs :-
-    array.fetch_items(A, N1, N2, Xs).
-
-array.bsearch(A, X, F) = MN :-
-    P = ( pred(X1::in, X2::in, C::out) is det :- C = F(X1, X2) ),
-    array.bsearch(A, X, P, MN).
-
-array.map(F, A1) = A2 :-
-    P = ( pred(X::in, Y::out) is det :- Y = F(X) ),
-    array.map(P, A1, A2).
-
-array_compare(A1, A2) = C :-
-    array_compare(C, A1, A2).
-
-array.elem(Index, Array) = array.lookup(Array, Index).
-
-array.unsafe_elem(Index, Array) = Elem :-
-    array.unsafe_lookup(Array, Index, Elem).
-
-'elem :='(Index, Array, Value) = array.set(Array, Index, Value).
-
-member(A, X) :-
+array.member(A, X) :-
      nondet_int_in_range(0, array.size(A) - 1, I0),
      X = A ^ elem(I0).

-% ---------------------------------------------------------------------------- %
+%-----------------------------------------------------------------------------%

      % array.sort/1 has type specialised versions for arrays of
      % ints and strings on the expectation that these constitute
@@ -2423,4 +2422,5 @@
      ).

  %------------------------------------------------------------------------------%
+:- end_module array.
  %------------------------------------------------------------------------------%
Index: library/hash_table.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/hash_table.m,v
retrieving revision 1.23
diff -u -r1.23 hash_table.m
--- library/hash_table.m	27 Jul 2010 17:03:58 -0000	1.23
+++ library/hash_table.m	6 May 2011 06:44:49 -0000
@@ -309,7 +309,7 @@
          AL = ht_cons(K, V, AL0),
          MayExpand = yes
      ),
-    array.unsafe_set(Buckets0, H, AL, Buckets),
+    array.unsafe_set(H, AL, Buckets0, Buckets),
      !HT ^ buckets := Buckets,
      (
          MayExpand = no
@@ -362,7 +362,7 @@
        else
          AL = ht_cons(K, V, AL0)
      ),
-    array.unsafe_set(Buckets0, H, AL, Buckets),
+    array.unsafe_set(H, AL, Buckets0, Buckets),
      !HT ^ buckets := Buckets,
      increase_occupants(!HT).

@@ -370,17 +370,17 @@

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

-det_update(HT0, K, V) = HT :-
-    H = find_slot(HT0, K),
-    Buckets0 = HT0 ^ buckets,
+det_update(!.HT, K, V) = !:HT :-
+    H = find_slot(!.HT, K),
+    Buckets0 = !.HT ^ buckets,
      array.unsafe_lookup(Buckets0, H, AL0),
      ( if alist_replace(AL0, K, V, AL1) then
          AL = AL1
        else
          throw(software_error("hash_table.det_update: key not found"))
      ),
-    array.unsafe_set(Buckets0, H, AL, Buckets),
-    HT = HT0 ^ buckets := Buckets.
+    array.unsafe_set(H, AL, Buckets0, Buckets),
+    !HT ^ buckets := Buckets.

  det_update(K, V, HT, det_update(HT, K, V)).

@@ -401,7 +401,7 @@
      array.unsafe_lookup(HT0 ^ buckets, H, AL0),
      ( if alist_remove(AL0, K, AL) then
          HT0 = ht(NumOccupants0, MaxOccupants, HashPred, Buckets0),
-        array.unsafe_set(Buckets0, H, AL, Buckets),
+        array.unsafe_set(H, AL, Buckets0, Buckets),
          NumOccupants = NumOccupants0 - 1,
          HT = ht(NumOccupants, MaxOccupants, HashPred, Buckets)
        else
@@ -505,10 +505,10 @@
  :- pred unsafe_insert(K::in, V::in, hash_pred(K)::in(hash_pred), int::in,
      buckets(K, V)::array_di, buckets(K, V)::array_uo) is det.

-unsafe_insert(K, V, HashPred, NumBuckets, Buckets0, Buckets) :-
+unsafe_insert(K, V, HashPred, NumBuckets, !Buckets) :-
      find_slot_2(HashPred, K, NumBuckets, H),
-    array.unsafe_lookup(Buckets0, H, AL0),
-    array.unsafe_set(Buckets0, H, ht_cons(K, V, AL0), Buckets).
+    array.unsafe_lookup(!.Buckets, H, AL0),
+    array.unsafe_set(H, ht_cons(K, V, AL0), !Buckets).

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

Index: library/io.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/io.m,v
retrieving revision 1.458
diff -u -r1.458 io.m
--- library/io.m	3 May 2011 04:35:01 -0000	1.458
+++ library/io.m	6 May 2011 06:30:34 -0000
@@ -4144,7 +4144,7 @@
          io.read_char(input_stream(Stream), CharResult, !IO),
          (
              CharResult = ok(Char),
-            array.set(!.Array, !.Pos, Char, !:Array),
+            array.set(!.Pos, Char, !Array),
              !:Pos = !.Pos + 1,
              io.read_into_array(Stream, !Array, !Pos, Size, !IO)
          ;
Index: library/random.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/random.m,v
retrieving revision 1.29
diff -u -r1.29 random.m
--- library/random.m	19 Apr 2006 05:17:55 -0000	1.29
+++ library/random.m	6 May 2011 06:34:11 -0000
@@ -128,7 +128,7 @@
  :- import_module int.

  :- type random.supply
-    ---> rs(int). % I(j)
+    --->    rs(int). % I(j)

  :- pred random.params(int::out, int::out, int::out) is det.	% a, c, m

@@ -176,29 +176,28 @@
  	% Index is mapped to, Next, to the permutation, and then ensures that
  	% Next is not generated again by swapping it with the image of I-1.

-random.permutation(List0, List, RS0, RS) :-
+random.permutation(List0, List, !RS) :-
  	Samples = array(List0),
  	Len = array.size(Samples),
-	perform_sampling(Len, Samples, [], List, RS0, RS).
+	perform_sampling(Len, Samples, [], List, !RS).

  :- pred perform_sampling(int, array(T), list(T), list(T),
  	random.supply, random.supply) is det.
  :- mode perform_sampling(in, array_di, in, out, mdi, muo) is det.
  :- mode perform_sampling(in, array_di, in, out, in, out) is det.

-perform_sampling(I, Record0, Order0, Order, RS0, RS) :-
+perform_sampling(I, !.Record, !Order, !RS) :-
  	( I =< 0 ->
-		Order = Order0,
-		RS = RS0
+        true
  	;
  		I1 = I - 1,
-		random.random(0, I, Index, RS0, RS1),
-		array.lookup(Record0, Index, Next),
-		array.lookup(Record0, I1, MaxImage),
-		Order1 = [Next | Order0],
-		array.set(Record0, Index, MaxImage, Record1),
-		array.set(Record1, I1, Next, Record2),
-		perform_sampling(I1, Record2, Order1, Order, RS1, RS)
+		random.random(0, I, Index, !RS),
+		array.lookup(!.Record, Index, Next),
+		array.lookup(!.Record, I1, MaxImage),
+		!:Order = [Next | !.Order],
+		array.set(Index, MaxImage, !Record),
+		array.set(I1, Next, !Record),
+		perform_sampling(I1, !.Record, !Order, !RS)
  	).

  %---------------------------------------------------------------------------%
@@ -212,15 +211,14 @@
  :- mode random.test_2(in, out, mdi, muo) is det.
  :- mode random.test_2(in, out, in, out) is det.

-random.test_2(N, Is, RS0, RS) :-
+random.test_2(N, Is, !RS) :-
  	( N > 0 ->
  		N1 = N - 1,
-		random.random(I, RS0, RS1),
-		random.test_2(N1, Is0, RS1, RS),
-		Is = [I|Is0]
+		random.random(I, !RS),
+		random.test_2(N1, Is0, !RS),
+		Is = [I | Is0]
  	;
-		Is = [],
-		RS = RS0
+		Is = []
  	).

  %---------------------------------------------------------------------------%
Index: library/svarray.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/svarray.m,v
retrieving revision 1.7
diff -u -r1.7 svarray.m
--- library/svarray.m	6 Mar 2007 05:48:34 -0000	1.7
+++ library/svarray.m	6 May 2011 06:45:43 -0000
@@ -78,21 +78,21 @@
  :- implementation.

  svarray.set(Index, Value, !Array) :-
-    array.set(!.Array, Index, Value, !:Array).
+    array.set(Index, Value, !Array).

  svarray.semidet_set(Index, Value, !Array) :-
-    array.semidet_set(!.Array, Index, Value, !:Array).
+    array.semidet_set(Index, Value, !Array).

  svarray.slow_set(Index, Value, !Array) :-
-    array.slow_set(!.Array, Index, Value, !:Array).
+    array.slow_set(Index, Value, !Array).

  svarray.semidet_slow_set(Index, Value, !Array) :-
-    array.semidet_slow_set(!.Array, Index, Value, !:Array).
+    array.semidet_slow_set(Index, Value, !Array).

  svarray.resize(Size, Init, !Array) :-
-    array.resize(!.Array, Size, Init, !:Array).
+    array.resize(Size, Init, !Array).

  svarray.shrink(Size, !Array) :-
-    array.shrink(!.Array, Size, !:Array).
+    array.shrink(Size, !Array).

  %-----------------------------------------------------------------------------%
Index: tests/general/array_test.m
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/general/array_test.m,v
retrieving revision 1.6
diff -u -r1.6 array_test.m
--- tests/general/array_test.m	29 Mar 2006 08:07:57 -0000	1.6
+++ tests/general/array_test.m	6 May 2011 07:58:41 -0000
@@ -35,13 +35,13 @@
  	write_message_int("AMax1: ", AMax1),
  	{ array__bsearch(A0, 4, Cmp, ABsearch) },
  	write_message_maybe_int("ABsearch: ", ABsearch),
-	{ array__set(A0, 8, 100, A1) },
+	{ array__set(8, 100, A0, A1) },
  	{ array__to_list(A1, As1) },
  	write_message_int_list("A1: ", As1),
-	{ array__resize(A1, 15, 1000, A2) },
+	{ array__resize(15, 1000, A1, A2) },
  	{ array__to_list(A2, As2) },
  	write_message_int_list("A2: ", As2),
-	{ array__shrink(A2, 10, A3) },
+	{ array__shrink(10, A2, A3) },
  	{ array__to_list(A3, As3) },
  	write_message_int_list("A3: ", As3),
  	{ A4 = array__sort(array(1 `..` 10)) },
Index: tests/general/mode_inf.m
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/general/mode_inf.m,v
retrieving revision 1.5
diff -u -r1.5 mode_inf.m
--- tests/general/mode_inf.m	4 Apr 2006 02:39:19 -0000	1.5
+++ tests/general/mode_inf.m	6 May 2011 07:59:10 -0000
@@ -18,7 +18,7 @@

  some_array_stuff(X, Y) :-
  	array__init(40, 80, A0),
-	array__set(A0, 37, X, A1),
+	array__set(37, X, A0, A1),
  	array__lookup(A1, 37, Y).

  some_backtracking_stuff(X, Y, Z) :- Y = X + 1, p(Z).
Index: tests/general/set_test.m
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/general/set_test.m,v
retrieving revision 1.3
diff -u -r1.3 set_test.m
--- tests/general/set_test.m	8 Jul 1997 16:49:14 -0000	1.3
+++ tests/general/set_test.m	6 May 2011 07:59:36 -0000
@@ -20,7 +20,7 @@
  	{ set_bbbtree__init(Set0) },
  	(
  		{ set_bbbtree__empty(Set0) },
-		{ set_bbbtree__size(Set0, 0) }
+		{ set_bbbtree__count(Set0, 0) }
  	->
  		{ true }
  	;
@@ -72,7 +72,7 @@
  	),
  	{ set_bbbtree__list_to_set([-2, 10, 0, -1, 2, -2, -2, 0], Set50) },
  	(
-		{ set_bbbtree__size(Set50, 5) },
+		{ set_bbbtree__count(Set50, 5) },
  		{ set_bbbtree__remove_least(Set50, -2, TempSet) }
  	->
  		{ Set60 = TempSet },
Index: tests/hard_coded/array_test2.m
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/hard_coded/array_test2.m,v
retrieving revision 1.1
diff -u -r1.1 array_test2.m
--- tests/hard_coded/array_test2.m	20 Jul 2010 07:38:46 -0000	1.1
+++ tests/hard_coded/array_test2.m	6 May 2011 08:03:09 -0000
@@ -61,12 +61,12 @@
      Elem = list.det_head(List),

      array.copy(Array, ArrayB),
-    ( semidet_set(Array, -1, Elem, _) ->
+    ( semidet_set(-1, Elem, Array, _) ->
          io.write_string("error: out of bounds set succeeded\n", !IO)
      ;
          io.write_string("good: out of bounds set averted\n", !IO)
      ),
-    ( semidet_set(ArrayB, 5, Elem, _) ->
+    ( semidet_set(5, Elem, ArrayB, _) ->
          io.write_string("error: out of bounds set succeeded\n", !IO)
      ;
          io.write_string("good: out of bounds set averted\n", !IO)
@@ -74,32 +74,32 @@

      some [!A] (
          array.from_list(List, !:A),
-        array.resize(!.A, list.length(List), Elem, !:A),
+        array.resize(list.length(List), Elem, !A),
          io.write_string("resize without resizing: ", !IO),
          io.write(!.A, !IO),
          io.nl(!IO),

-        array.resize(!.A, 1 + list.length(List)//2, Elem, !:A),
+        array.resize(1 + list.length(List)//2, Elem, !A),
          io.write_string("shrink: ", !IO),
          io.write(!.A, !IO),
          io.nl(!IO),

-        array.resize(!.A, list.length(List), Elem, !:A),
+        array.resize(list.length(List), Elem, !A),
          io.write_string("enlarge: ", !IO), % embiggen
          io.write(!.A, !IO),
          io.nl(!IO),

-        array.resize(!.A, 0, Elem, !:A),
+        array.resize(0, Elem, !A),
          io.write_string("empty: ", !IO),
          io.write(!.A, !IO),
          io.nl(!IO),

-        array.resize(!.A, 0, Elem, !:A),
+        array.resize(0, Elem, !A),
          io.write_string("still empty: ", !IO),
          io.write(!.A, !IO),
          io.nl(!IO),

-        array.resize(!.A, 3, Elem, !:A),
+        array.resize(3, Elem, !A),
          io.write_string("nonempty from empty: ", !IO),
          io.write(!.A, !IO),
          io.nl(!IO)
Index: tests/hard_coded/lp.m
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/hard_coded/lp.m,v
retrieving revision 1.10
diff -u -r1.10 lp.m
--- tests/hard_coded/lp.m	5 May 2011 03:59:00 -0000	1.10
+++ tests/hard_coded/lp.m	6 May 2011 08:04:34 -0000
@@ -364,7 +364,7 @@
  	_Rows = Rows0 + 1, Cols = Cols0 + 1,
  	Index = J * Cols + K,
  	mkuniq(Tableau0, Tableau1),
-	array__set(Tableau1, Index, R, Tableau).
+	array__set(Index, R, Tableau1, Tableau).

  :- pred mkuniq(array(float)::in, array(float)::array_uo) is det.

Index: tests/hard_coded/reuse_array.m
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/hard_coded/reuse_array.m,v
retrieving revision 1.1
diff -u -r1.1 reuse_array.m
--- tests/hard_coded/reuse_array.m	3 May 2011 04:31:19 -0000	1.1
+++ tests/hard_coded/reuse_array.m	6 May 2011 08:00:04 -0000
@@ -37,7 +37,7 @@
      % Struct2 can and should be reused instead.
      Struct3 = struct(3, dummy),
      impure addr(Struct3, Addr3),
-    array.unsafe_set(Array0, 3, Struct3, Array),
+    array.unsafe_set(3, Struct3, Array0, Array),
      unused(Struct3 ^ f),

      % Struct3 should NOT be reused for Struct4, as it is shared with Array.

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