[m-rev.] diff: change argument ordering in eqvclass and queue modules
Julien Fischer
juliensf at csse.unimelb.edu.au
Tue May 3 15:10:33 AEST 2011
Branches: main
Change the argument ordering of predicates in the eqvclass and queue modules in
order to make the more conducive to the use of state variable notation.
library/eqvclass.m:
library/queue.m:
Make the above changes.
Shift function definitions so that they placed with
the corresponding predicate definitions rather than
all being grouped at the end of the module.
library/sveqvclass.m:
library/svqueue.m:
compiler/common.m:
compiler/ctgc.selector.m:
compiler/dead_proc_elim.m:
compiler/matching.m:
compiler/modes.m:
compiler/recompilation.usage.m:
compiler/unify_proc.m:a
tests/hard_coded/type_to_term_bug.m:
Conform to the above change and remove dependencies on the
sv{eqvclass,queue} modules.
NEWS:
Announce the change.
Julien.
Index: NEWS
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/NEWS,v
retrieving revision 1.560
diff -u -r1.560 NEWS
--- NEWS 3 May 2011 04:34:52 -0000 1.560
+++ NEWS 3 May 2011 05:01:05 -0000
@@ -13,8 +13,8 @@
* We have improved Unicode support in the standard library.
* We have changed the argument order of many of the predicates in the
- bimap, map, and multi_map modules in order to make them more conducive
- to the use of state variable notation.
+ bimap, eqvclass, map, multi_map and queue modules in order to make
+ them more conducive to the use of state variable notation.
DETAILED LISTING
@@ -31,15 +31,20 @@
* The argument of the following predicates has been changed in order to
make them more conducive to the use of state variable notation:
- bimap.insert/4, bimap.det_insert/4, bimap.set/4, map.insert/4,
- map.det_insert/4, map.det_insert_from_corresponding_lists/4,
+ 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,
multi_map.insert/4, multi_map.det_insert/4, multi_map.update/4,
multi_map.det_update/4, multi_map.det_replace/4, multi_map.set/4,
multi_map.add/4, multi_map.delete/4, multi_map.remove/4, and
- multi_map.remove_smallest/4.
+ multi_map.remove_smallest/4, queue.put/3, queue.put_list/3,
+ 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.
NEWS for Mercury 11.01
Index: compiler/common.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/common.m,v
retrieving revision 1.111
diff -u -r1.111 common.m
--- compiler/common.m 3 May 2011 04:34:53 -0000 1.111
+++ compiler/common.m 3 May 2011 05:07:36 -0000
@@ -111,7 +111,6 @@
:- import_module pair.
:- import_module require.
:- import_module set.
-:- import_module sveqvclass.
:- import_module term.
%---------------------------------------------------------------------------%
@@ -311,7 +310,7 @@
OldStruct)
->
OldStruct = structure(OldVar, _),
- sveqvclass.ensure_equivalence(Var, OldVar, VarEqv1, VarEqv),
+ eqvclass.ensure_equivalence(Var, OldVar, VarEqv1, VarEqv),
CommonInfo = CommonInfo0 ^ var_eqv := VarEqv,
simplify_info_set_common_info(CommonInfo, !Info),
(
@@ -493,7 +492,7 @@
record_equivalence(Var1, Var2, !Info) :-
simplify_info_get_common_info(!.Info, CommonInfo0),
VarEqv0 = CommonInfo0 ^ var_eqv,
- eqvclass.ensure_equivalence(VarEqv0, Var1, Var2, VarEqv),
+ eqvclass.ensure_equivalence(Var1, Var2, VarEqv0, VarEqv),
CommonInfo = CommonInfo0 ^ var_eqv := VarEqv,
simplify_info_set_common_info(CommonInfo, !Info).
Index: compiler/ctgc.selector.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ctgc.selector.m,v
retrieving revision 1.30
diff -u -r1.30 ctgc.selector.m
--- compiler/ctgc.selector.m 3 May 2011 04:31:19 -0000 1.30
+++ compiler/ctgc.selector.m 3 May 2011 04:35:30 -0000
@@ -291,7 +291,7 @@
[allow_reset, specified([promise_implied, value, value, output])]).
type_contains_subtype_1(ModuleInfo, FromType, ToType, Contains) :-
- queue.put(queue.init, FromType, Queue0),
+ queue.put(FromType, queue.init, Queue0),
type_contains_subtype_2(ModuleInfo, ToType, Queue0, _Queue,
set.init, _SeenTypes, Contains).
@@ -304,7 +304,7 @@
set(mer_type)::in, set(mer_type)::out, bool::out) is det.
type_contains_subtype_2(ModuleInfo, ToType, !Queue, !SeenTypes, Contains) :-
- ( queue.get(!.Queue, FromType, !:Queue) ->
+ ( queue.get(FromType, !Queue) ->
( set.contains(!.SeenTypes, FromType) ->
type_contains_subtype_2(ModuleInfo, ToType, !Queue, !SeenTypes,
Contains)
@@ -314,7 +314,7 @@
( list.member(ToType, ArgTypes) ->
Contains = yes
;
- queue.put_list(!.Queue, ArgTypes, !:Queue),
+ queue.put_list(ArgTypes, !Queue),
type_contains_subtype_2(ModuleInfo, ToType, !Queue, !SeenTypes,
Contains)
)
Index: compiler/dead_proc_elim.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/dead_proc_elim.m,v
retrieving revision 1.140
diff -u -r1.140 dead_proc_elim.m
--- compiler/dead_proc_elim.m 3 May 2011 04:34:53 -0000 1.140
+++ compiler/dead_proc_elim.m 3 May 2011 05:06:19 -0000
@@ -98,7 +98,6 @@
:- import_module set_tree234.
:- import_module set.
:- import_module string.
-:- import_module svqueue.
%-----------------------------------------------------------------------------%
@@ -191,7 +190,7 @@
dead_proc_initialize_procs(_PredId, [], !Queue, !Needed).
dead_proc_initialize_procs(PredId, [ProcId | ProcIds], !Queue, !Needed) :-
Entity = entity_proc(PredId, ProcId),
- svqueue.put(Entity, !Queue),
+ queue.put(Entity, !Queue),
map.set(Entity, not_eliminable, !Needed),
dead_proc_initialize_procs(PredId, ProcIds, !Queue, !Needed).
@@ -208,7 +207,7 @@
PragmaProc = pragma_exported_proc(_Lang, PredId, ProcId,
_ExportName, _Ctxt),
Entity = entity_proc(PredId, ProcId),
- svqueue.put(Entity, !Queue),
+ queue.put(Entity, !Queue),
map.set(Entity, not_eliminable, !Needed),
dead_proc_initialize_pragma_exports(PragmaProcs, !Queue, !Needed).
@@ -223,7 +222,7 @@
dead_proc_initialize_init_fn_procs([PPId | PPIds], !Queue, !Needed) :-
PPId = proc(PredId, ProcId),
Entity = entity_proc(PredId, ProcId),
- svqueue.put(Entity, !Queue),
+ queue.put(Entity, !Queue),
map.set(Entity, not_eliminable, !Needed),
dead_proc_initialize_init_fn_procs(PPIds, !Queue, !Needed).
@@ -254,7 +253,7 @@
semidet_succeed
->
Entity = entity_type_ctor(ModuleName, TypeName, Arity),
- svqueue.put(Entity, !Queue),
+ queue.put(Entity, !Queue),
map.set(Entity, not_eliminable, !Needed)
;
true
@@ -304,7 +303,7 @@
get_class_interface_pred_proc(ClassProc, !Queue, !Needed) :-
ClassProc = hlds_class_proc(PredId, ProcId),
Entity = entity_proc(PredId, ProcId),
- svqueue.put(Entity, !Queue),
+ queue.put(Entity, !Queue),
map.set(Entity, not_eliminable, !Needed).
%-----------------------------------------------------------------------------%
@@ -314,7 +313,7 @@
dead_proc_examine(!.Queue, !.Examined, ModuleInfo, !Needed) :-
% See if the queue is empty.
- ( svqueue.get(Entity, !Queue) ->
+ ( queue.get(Entity, !Queue) ->
% See if the next element has been examined before.
( set_tree234.contains(!.Examined, Entity) ->
dead_proc_examine(!.Queue, !.Examined, ModuleInfo, !Needed)
@@ -386,7 +385,7 @@
dead_proc_examine_refs([Ref | Refs], !Queue, !Needed) :-
Ref = proc(PredId, ProcId),
Entity = entity_proc(PredId, ProcId),
- svqueue.put(Entity, !Queue),
+ queue.put(Entity, !Queue),
map.set(Entity, not_eliminable, !Needed),
dead_proc_examine_refs(Refs, !Queue, !Needed).
@@ -497,7 +496,7 @@
;
GoalExpr = plain_call(PredId, ProcId, _,_,_,_),
Entity = entity_proc(PredId, ProcId),
- queue.put(!.Queue, Entity, !:Queue),
+ queue.put(Entity, !Queue),
( proc(PredId, ProcId) = CurrProc ->
trace [io(!IO), compile_time(flag("dead_proc_elim"))] (
io.write_string("plain_call recursive ", !IO),
@@ -554,7 +553,7 @@
io.write_int(proc_id_to_int(ProcId), !IO),
io.nl(!IO)
),
- svqueue.put(Entity, !Queue),
+ queue.put(Entity, !Queue),
map.set(Entity, not_eliminable, !Needed)
;
GoalExpr = unify(_LHS, _RHS, _UniModes, Unification, _UnifyContext),
@@ -589,7 +588,7 @@
io.nl(!IO)
)
),
- svqueue.put(Entity, !Queue),
+ queue.put(Entity, !Queue),
map.set(Entity, not_eliminable, !Needed)
;
( ConsId = cons(_, _, _)
@@ -954,7 +953,7 @@
dead_pred_elim_add_entity(entity_type_ctor(_, _, _), !Queue, !Preds).
dead_pred_elim_add_entity(entity_table_struct(_, _), !Queue, !Preds).
dead_pred_elim_add_entity(entity_proc(PredId, _), !Queue, !Preds) :-
- svqueue.put(PredId, !Queue),
+ queue.put(PredId, !Queue),
set_tree234.insert(PredId, !Preds).
:- pred dead_pred_elim_initialize(pred_id::in,
@@ -1013,7 +1012,7 @@
)
->
set_tree234.insert(qualified(PredModule, PredName), !NeededNames),
- svqueue.put(PredId, !Queue)
+ queue.put(PredId, !Queue)
;
true
),
@@ -1027,7 +1026,7 @@
some [!Queue, !Examined, !Needed] (
!.DeadInfo = pred_elim_info(ModuleInfo, !:Queue, !:Examined,
!:Needed, NeededNames),
- ( svqueue.get(PredId, !Queue) ->
+ ( queue.get(PredId, !Queue) ->
( set_tree234.contains(!.Examined, PredId) ->
!:DeadInfo = pred_elim_info(ModuleInfo, !.Queue, !.Examined,
!.Needed, NeededNames)
@@ -1157,7 +1156,7 @@
predicate_table_search_sym(PredicateTable,
may_be_partially_qualified, Name, PredIds)
->
- svqueue.put_list(PredIds, !Queue)
+ queue.put_list(PredIds, !Queue)
;
true
),
Index: compiler/frameopt.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/frameopt.m,v
retrieving revision 1.122
diff -u -r1.122 frameopt.m
--- compiler/frameopt.m 3 May 2011 04:34:54 -0000 1.122
+++ compiler/frameopt.m 3 May 2011 05:06:39 -0000
@@ -167,7 +167,6 @@
:- import_module require.
:- import_module set.
:- import_module string.
-:- import_module svqueue.
:- import_module svset.
%-----------------------------------------------------------------------------%
@@ -1619,7 +1618,7 @@
;
NeedsFrame = block_needs_frame,
map.det_insert(Label, block_needs_frame, !OrdNeedsFrame),
- svqueue.put(Label, !Queue)
+ queue.put(Label, !Queue)
)
;
BlockType = exit_block(_)
@@ -1675,7 +1674,7 @@
!.CanTransform = can_transform,
( !.PropagationStepsLeft < 0 ->
!:CanTransform = cannot_transform
- ; svqueue.get(Label, !Queue) ->
+ ; queue.get(Label, !Queue) ->
!:PropagationStepsLeft = !.PropagationStepsLeft - 1,
svset.insert(Label, !AlreadyProcessed),
map.lookup(BlockMap, Label, BlockInfo),
@@ -1694,7 +1693,7 @@
% to do that for exit frames.
list.filter(set.contains(!.AlreadyProcessed),
successors(BlockInfo), _, UnprocessedSuccessors),
- svqueue.put_list(UnprocessedSuccessors, !Queue)
+ queue.put_list(UnprocessedSuccessors, !Queue)
;
BlockType = entry_block(_),
!:CanTransform = cannot_transform
@@ -1726,7 +1725,7 @@
!.CanTransform = can_transform,
( !.PropagationStepsLeft < 0 ->
!:CanTransform = cannot_transform
- ; svqueue.get(Label, !Queue) ->
+ ; queue.get(Label, !Queue) ->
!:PropagationStepsLeft = !.PropagationStepsLeft - 1,
( map.search(RevMap, Label, PredecessorsPrime) ->
Predecessors = PredecessorsPrime
@@ -1745,7 +1744,7 @@
!OrdNeedsFrame, !CanTransform),
% XXX map.lookup(BlockMap, Label, BlockInfo),
% XXX Successors = successors(BlockInfo),
- svqueue.put_list(NowNeedFrameLabels, !Queue),
+ queue.put_list(NowNeedFrameLabels, !Queue),
propagate_frame_requirement_to_predecessors(!.Queue, BlockMap,
RevMap, !OrdNeedsFrame, !PropagationStepsLeft, !CanTransform)
;
Index: compiler/matching.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/matching.m,v
retrieving revision 1.15
diff -u -r1.15 matching.m
--- compiler/matching.m 3 May 2011 04:34:55 -0000 1.15
+++ compiler/matching.m 3 May 2011 05:06:52 -0000
@@ -95,7 +95,6 @@
:- import_module require.
:- import_module string.
:- import_module term.
-:- import_module svqueue.
% The stack optimization graph is a bipartite graph, whose two node types
% are cost nodes and benefit nodes. Each node represents a copy of an
@@ -484,7 +483,7 @@
stack_slot_graph, matching) = edge_list is semidet.
augpath_bf(Queue0, Seen0, Graph, Matching) = Path :-
- queue.get(Queue0, NodePath, Queue1),
+ queue.get(NodePath, Queue0, Queue1),
NodePath = benefit_node_and_edge_list(BenefitNode, Path0),
Graph = stack_slot_graph(_, BenefitToCostsMap),
map.lookup(BenefitToCostsMap, BenefitNode, AdjCostNodes),
@@ -534,7 +533,7 @@
NewPath = [BenefitNode - CostNode | Path],
BenefitNodeAndEdgeList =
benefit_node_and_edge_list(AdjBenefitNode, NewPath),
- svqueue.put(BenefitNodeAndEdgeList, !Queue)
+ queue.put(BenefitNodeAndEdgeList, !Queue)
;
true
),
Index: compiler/modes.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/modes.m,v
retrieving revision 1.394
diff -u -r1.394 modes.m
--- compiler/modes.m 3 May 2011 04:34:56 -0000 1.394
+++ compiler/modes.m 3 May 2011 04:35:31 -0000
@@ -874,7 +874,7 @@
Specs) :-
module_info_get_proc_requests(!.ModuleInfo, Requests0),
get_req_queue(Requests0, RequestQueue0),
- ( queue.get(RequestQueue0, PredProcId, RequestQueue1) ->
+ ( queue.get(PredProcId, RequestQueue0, RequestQueue1) ->
set_req_queue(RequestQueue1, Requests0, Requests1),
module_info_set_proc_requests(Requests1, !ModuleInfo),
Index: compiler/recompilation.usage.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/recompilation.usage.m,v
retrieving revision 1.54
diff -u -r1.54 recompilation.usage.m
--- compiler/recompilation.usage.m 3 May 2011 04:34:58 -0000 1.54
+++ compiler/recompilation.usage.m 3 May 2011 04:35:31 -0000
@@ -635,11 +635,11 @@
queue(item_id)::in,
recompilation_usage_info::in, recompilation_usage_info::out) is det.
-process_imported_item_queue_2(Queue0, !Info) :-
- ( queue.get(Queue0, Item, Queue) ->
+process_imported_item_queue_2(!.Queue, !Info) :-
+ ( queue.get(Item, !Queue) ->
Item = item_id(ItemType, ItemId),
find_items_used_by_item(ItemType, ItemId, !Info),
- process_imported_item_queue_2(Queue, !Info)
+ process_imported_item_queue_2(!.Queue, !Info)
;
true
).
@@ -658,7 +658,7 @@
do_record_used_pred_or_func(PredOrFunc),
IdSet0, IdSet, !Info),
ItemSet = update_pred_or_func_set(ItemSet0, ItemType, IdSet),
- !:Info = !.Info ^ used_items := ItemSet.
+ !Info ^ used_items := ItemSet.
:- pred do_record_used_pred_or_func(pred_or_func::in,
module_qualifier::in, sym_name::in, arity::in, bool::out,
@@ -701,7 +701,7 @@
record_resolved_item(SymName, Arity, do_record_used_functor,
IdSet0, IdSet, !Info),
ItemSet = ItemSet0 ^ functors := IdSet,
- !:Info = !.Info ^ used_items := ItemSet.
+ !Info ^ used_items := ItemSet.
:- pred do_record_used_functor(module_qualifier::in,
sym_name::in, arity::in, bool::out, resolved_functor_map::in,
@@ -1422,7 +1422,7 @@
( ItemType = typeclass_item ->
Classes0 = !.Info ^ used_typeclasses,
set.insert(Classes0, ItemName, Classes),
- !:Info = !.Info ^ used_typeclasses := Classes
+ !Info ^ used_typeclasses := Classes
;
true
),
@@ -1436,8 +1436,8 @@
true
;
Queue0 = !.Info ^ item_queue,
- queue.put(Queue0, item_id(ItemType, ItemName), Queue),
- !:Info = !.Info ^ item_queue := Queue,
+ queue.put(item_id(ItemType, ItemName), Queue0, Queue),
+ !Info ^ item_queue := Queue,
record_imported_item(ItemType, ItemName, !Info),
record_expanded_items_used_by_item(ItemType, ItemName, !Info)
Index: compiler/unify_proc.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/unify_proc.m,v
retrieving revision 1.217
diff -u -r1.217 unify_proc.m
--- compiler/unify_proc.m 3 May 2011 04:34:59 -0000 1.217
+++ compiler/unify_proc.m 3 May 2011 04:35:31 -0000
@@ -368,7 +368,7 @@
% Insert the pred_proc_id into the request queue.
module_info_get_proc_requests(!.ModuleInfo, Requests0),
get_req_queue(Requests0, ReqQueue0),
- queue.put(ReqQueue0, proc(PredId, ProcId), ReqQueue),
+ queue.put(proc(PredId, ProcId), ReqQueue0, ReqQueue),
set_req_queue(ReqQueue, Requests0, Requests),
module_info_set_proc_requests(Requests, !ModuleInfo)
).
Index: library/eqvclass.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/eqvclass.m,v
retrieving revision 1.26
diff -u -r1.26 eqvclass.m
--- library/eqvclass.m 3 May 2011 04:35:01 -0000 1.26
+++ library/eqvclass.m 3 May 2011 04:35:34 -0000
@@ -65,7 +65,7 @@
% if it isn't, it is created without any equivalence relationships.
%
:- func eqvclass.ensure_element(eqvclass(T), T) = eqvclass(T).
-:- pred eqvclass.ensure_element(eqvclass(T)::in, T::in, eqvclass(T)::out)
+:- pred eqvclass.ensure_element(T::in, eqvclass(T)::in, eqvclass(T)::out)
is det.
% Make an element known to the equivalence class.
@@ -73,14 +73,14 @@
% it is created without any equivalence relationships.
%
:- func eqvclass.new_element(eqvclass(T), T) = eqvclass(T).
-:- pred eqvclass.new_element(eqvclass(T)::in, T::in, eqvclass(T)::out) is det.
+:- pred eqvclass.new_element(T::in, eqvclass(T)::in, eqvclass(T)::out) is det.
% Make two elements of the equivalence class equivalent.
% It is ok if they already are.
%
:- func eqvclass.ensure_equivalence(eqvclass(T), T, T) = eqvclass(T).
-:- pred eqvclass.ensure_equivalence(eqvclass(T)::in, T::in, T::in,
- eqvclass(T)::out) is det.
+:- pred eqvclass.ensure_equivalence(T::in, T::in,
+ eqvclass(T)::in, eqvclass(T)::out) is det.
:- func eqvclass.ensure_corresponding_equivalences(list(T), list(T),
eqvclass(T)) = eqvclass(T).
@@ -91,8 +91,8 @@
% It is an error if they are already equivalent.
%
:- func eqvclass.new_equivalence(eqvclass(T), T, T) = eqvclass(T).
-:- pred eqvclass.new_equivalence(eqvclass(T)::in, T::in, T::in,
- eqvclass(T)::out) is det.
+:- pred eqvclass.new_equivalence(T::in, T::in,
+ eqvclass(T)::in, eqvclass(T)::out) is det.
% Test if two elements are equivalent.
%
@@ -140,6 +140,8 @@
% from the given equivalence class.
%
:- func eqvclass.remove_equivalent_elements(eqvclass(T), T) = eqvclass(T).
+:- pred eqvclass.remove_equivalent_elements(T::in,
+ eqvclass(T)::in, eqvclass(T)::out) is det.
% Given a function, divide each partition in the original equivalence class
% so that two elements of the original partition end up in the same
@@ -170,6 +172,9 @@
:- type partition_id == int.
+eqvclass.init = EqvClass :-
+ eqvclass.init(EqvClass).
+
eqvclass.init(EqvClass) :-
map.init(PartitionMap),
map.init(ElementMap),
@@ -183,8 +188,11 @@
ElementMap = EqvClass ^ keys,
map.search(ElementMap, Element, PartitionId).
-eqvclass.ensure_element(EqvClass0, Element, EqvClass) :-
- eqvclass.ensure_element_partition_id(Element, _, EqvClass0, EqvClass).
+eqvclass.ensure_element(!.EqvClass, X) = !:EqvClass :-
+ eqvclass.ensure_element(X, !EqvClass).
+
+eqvclass.ensure_element(Element, !EqvClass) :-
+ eqvclass.ensure_element_partition_id(Element, _, !EqvClass).
eqvclass.ensure_element_partition_id(Element, Id, !EqvClass) :-
ElementMap = !.EqvClass ^ keys,
@@ -194,12 +202,15 @@
eqvclass.add_element(Element, Id, !EqvClass)
).
-eqvclass.new_element(EqvClass0, Element, EqvClass) :-
- ElementMap0 = EqvClass0 ^ keys,
+eqvclass.new_element(!.EqvClass, X) = !:EqvClass :-
+ eqvclass.new_element(X, !EqvClass).
+
+eqvclass.new_element(Element, !EqvClass) :-
+ ElementMap0 = !.EqvClass ^ keys,
( map.search(ElementMap0, Element, _OldId) ->
error("new element is already in equivalence class")
;
- eqvclass.add_element(Element, _, EqvClass0, EqvClass)
+ eqvclass.add_element(Element, _, !EqvClass)
).
:- pred eqvclass.add_element(T::in, partition_id::out,
@@ -213,7 +224,10 @@
map.det_insert(Id, Partition, PartitionMap0, PartitionMap),
!:EqvClass = eqvclass(Counter, PartitionMap, ElementMap).
-eqvclass.ensure_equivalence(EqvClass0, ElementA, ElementB, EqvClass) :-
+eqvclass.ensure_equivalence(!.EqvClass, X, Y) = !:EqvClass :-
+ eqvclass.ensure_equivalence(X, Y, !EqvClass).
+
+eqvclass.ensure_equivalence(ElementA, ElementB, EqvClass0, EqvClass) :-
% The following code is logically equivalent to this code:
%
% eqvclass.ensure_equivalence(EqvClass0, ElementA, ElementB, EqvClass) :-
@@ -266,7 +280,10 @@
)
).
-eqvclass.new_equivalence(EqvClass0, ElementA, ElementB, EqvClass) :-
+eqvclass.new_equivalence(!.EqvClass, X, Y) = !:EqvClass :-
+ eqvclass.new_equivalence(X, Y, !EqvClass).
+
+eqvclass.new_equivalence(ElementA, ElementB, EqvClass0, EqvClass) :-
% This code is the same as eqvclass.ensure_equivalence, with the
% exception that we abort if IdA = IdB in EqvClass0.
@@ -314,7 +331,7 @@
eqvclass.ensure_corresponding_equivalences([_ | _], [], !EqvClass) :-
error("eqvclass.ensure_corresponding_equivalences: list mismatch").
eqvclass.ensure_corresponding_equivalences([H1 | T1], [H2 | T2], !EqvClass) :-
- eqvclass.ensure_equivalence(!.EqvClass, H1, H2, !:EqvClass),
+ eqvclass.ensure_equivalence(H1, H2, !EqvClass),
eqvclass.ensure_corresponding_equivalences(T1, T2, !EqvClass).
eqvclass.ensure_corresponding_equivalences(L1, L2, EqvClass0) = EqvClass :-
@@ -371,14 +388,20 @@
map.search(ElementMap, Element, Id),
eqvclass.same_eqvclass_list_2(ElementMap, Elements, Id).
+eqvclass.partition_set(EqvClass) = S :-
+ eqvclass.partition_set(EqvClass, S).
+
eqvclass.partition_set(EqvClass0, PartitionSet) :-
eqvclass.partition_ids(EqvClass0, Ids),
eqvclass.partitions(EqvClass0, Ids, PartitionList),
set.list_to_set(PartitionList, PartitionSet).
-eqvclass.partition_list(EqvClass0, PartitionList) :-
- eqvclass.partition_ids(EqvClass0, Ids),
- eqvclass.partitions(EqvClass0, Ids, PartitionList).
+eqvclass.partition_list(EqvClass) = Xs :-
+ eqvclass.partition_list(EqvClass, Xs).
+
+eqvclass.partition_list(EqvClass, PartitionList) :-
+ eqvclass.partition_ids(EqvClass, Ids),
+ eqvclass.partitions(EqvClass, Ids, PartitionList).
% Convert a list of partition ids to a list of partitions.
@@ -412,12 +435,16 @@
error("partition id not known to equivalence class")
).
-%---------------------------------------------------------------------------%
+eqvclass.partition_set_to_eqvclass(Set) = EqvClass :-
+ eqvclass.partition_set_to_eqvclass(Set, EqvClass).
eqvclass.partition_set_to_eqvclass(SetSet, EqvClass) :-
set.to_sorted_list(SetSet, ListSet),
eqvclass.partition_list_to_eqvclass(ListSet, EqvClass).
+eqvclass.partition_list_to_eqvclass(Xs) = EqvClass :-
+ eqvclass.partition_list_to_eqvclass(Xs, EqvClass).
+
eqvclass.partition_list_to_eqvclass([], EqvClass) :-
eqvclass.init(EqvClass).
eqvclass.partition_list_to_eqvclass([Partition | Ps], EqvClass) :-
@@ -445,38 +472,6 @@
map.det_insert(Element, Id, !ElementMap),
eqvclass.make_partition(Elements, Id, !ElementMap).
-%---------------------------------------------------------------------------%
-%---------------------------------------------------------------------------%
-% Ralph Becket <rwab1 at cl.cam.ac.uk> 29/04/99
-% Function forms added.
-
-eqvclass.init = EC :-
- eqvclass.init(EC).
-
-eqvclass.ensure_element(EC1, X) = EC2 :-
- eqvclass.ensure_element(EC1, X, EC2).
-
-eqvclass.new_element(EC1, X) = EC2 :-
- eqvclass.new_element(EC1, X, EC2).
-
-eqvclass.ensure_equivalence(EC1, X, Y) = EC2 :-
- eqvclass.ensure_equivalence(EC1, X, Y, EC2).
-
-eqvclass.new_equivalence(EC1, X, Y) = EC2 :-
- eqvclass.new_equivalence(EC1, X, Y, EC2).
-
-eqvclass.partition_set(EC) = S :-
- eqvclass.partition_set(EC, S).
-
-eqvclass.partition_list(EC) = Xs :-
- eqvclass.partition_list(EC, Xs).
-
-eqvclass.partition_set_to_eqvclass(S) = EC :-
- eqvclass.partition_set_to_eqvclass(S, EC).
-
-eqvclass.partition_list_to_eqvclass(Xs) = EC :-
- eqvclass.partition_list_to_eqvclass(Xs, EC).
-
eqvclass.get_equivalent_elements(eqvclass(_, PartitionMap, ElementMap), X) =
( Eqv = map.search(PartitionMap, map.search(ElementMap, X)) ->
Eqv
@@ -484,9 +479,12 @@
set.make_singleton_set(X)
).
-eqvclass.get_minimum_element(EC, X) =
- list.det_head(set.to_sorted_list(
- eqvclass.get_equivalent_elements(EC, X))).
+eqvclass.get_minimum_element(EqvClass, X) =
+ list.det_head(
+ set.to_sorted_list(eqvclass.get_equivalent_elements(EqvClass, X))).
+
+eqvclass.remove_equivalent_elements(X, !EqvClass) :-
+ !:EqvClass = remove_equivalent_elements(!.EqvClass, X).
eqvclass.remove_equivalent_elements(eqvclass(Id, P0, E0), X) =
eqvclass(Id, P, E) :-
@@ -560,3 +558,7 @@
map.det_update(Item, NewId, !Keys)
).
+
+%---------------------------------------------------------------------------%
+:- end_module eqvclass.
+%---------------------------------------------------------------------------%
Index: library/queue.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/queue.m,v
retrieving revision 1.35
diff -u -r1.35 queue.m
--- library/queue.m 6 Mar 2007 05:48:33 -0000 1.35
+++ library/queue.m 29 Apr 2011 12:47:46 -0000
@@ -32,8 +32,8 @@
% `queue.init(Queue)' is true iff `Queue' is an empty queue.
%
-:- pred queue.init(queue(T)::out) is det.
:- func queue.init = queue(T).
+:- pred queue.init(queue(T)::out) is det.
% 'queue_equal(Q1, Q2)' is true iff Q1 and Q2 contain the same
% elements in the same order.
@@ -50,41 +50,41 @@
%
:- pred queue.is_full(queue(T)::in) is semidet.
- % `queue.put(Queue0, Elem, Queue)' is true iff `Queue' is the queue
+ % `queue.put(Elem, Queue0, Queue)' is true iff `Queue' is the queue
% which results from appending `Elem' onto the end of `Queue0'.
%
-:- pred queue.put(queue(T)::in, T::in, queue(T)::out) is det.
:- func queue.put(queue(T), T) = queue(T).
+:- pred queue.put(T::in, queue(T)::in, queue(T)::out) is det.
- % `queue.put_list(Queue0, Elems, Queue)' is true iff `Queue' is the queue
+ % `queue.put_list(Elems, Queue0, Queue)' is true iff `Queue' is the queue
% which results from inserting the items in the list `Elems' into `Queue0'.
%
-:- pred queue.put_list(queue(T)::in, list(T)::in, queue(T)::out) is det.
:- func queue.put_list(queue(T), list(T)) = queue(T).
+:- pred queue.put_list(list(T)::in, queue(T)::in, queue(T)::out) is det.
% `queue.first(Queue, Elem)' is true iff `Queue' is a non-empty queue
% whose first element is `Elem'.
%
:- pred queue.first(queue(T)::in, T::out) is semidet.
- % `queue.get(Queue0, Elem, Queue)' is true iff `Queue0' is a non-empty
+ % `queue.get(Elem, Queue0, Queue)' is true iff `Queue0' is a non-empty
% queue whose first element is `Elem', and `Queue' the queue which results
% from removing that element from the front of `Queue0'.
%
-:- pred queue.get(queue(T)::in, T::out, queue(T)::out) is semidet.
+:- pred queue.get(T::out, queue(T)::in, queue(T)::out) is semidet.
% `queue.length(Queue, Length)' is true iff `Queue' is a queue
% containing `Length' elements.
%
-:- pred queue.length(queue(T)::in, int::out) is det.
:- func queue.length(queue(T)) = int.
+:- pred queue.length(queue(T)::in, int::out) is det.
% `queue.list_to_queue(List, Queue)' is true iff `Queue' is a queue
% containing the elements of List, with the first element of List at
% the head of the queue.
%
-:- pred queue.list_to_queue(list(T)::in, queue(T)::out) is det.
:- func queue.list_to_queue(list(T)) = queue(T).
+:- pred queue.list_to_queue(list(T)::in, queue(T)::out) is det.
% A synonym for queue.list_to_queue/1.
%
@@ -94,30 +94,30 @@
%
:- func queue.to_list(queue(T)) = list(T).
- % `queue.delete_all(Queue0, Elem, Queue)' is true iff `Queue' is the same
+ % `queue.delete_all(Elem, Queue0, Queue)' is true iff `Queue' is the same
% queue as `Queue0' with all occurrences of `Elem' removed from it.
%
-:- pred queue.delete_all(queue(T)::in, T::in, queue(T)::out) is det.
:- func queue.delete_all(queue(T), T) = queue(T).
+:- pred queue.delete_all(T::in, queue(T)::in, queue(T)::out) is det.
% `queue.put_on_front(Queue0, Elem) = Queue' pushes `Elem' on to
% the front of `Queue0', giving `Queue'.
%
:- func queue.put_on_front(queue(T), T) = queue(T).
-:- pred queue.put_on_front(queue(T)::in, T::in, queue(T)::out) is det.
+:- pred queue.put_on_front(T::in, queue(T)::in, queue(T)::out) is det.
% `queue.put_list_on_front(Queue0, Elems) = Queue' pushes `Elems'
% on to the front of `Queue0', giving `Queue' (the Nth member
% of `Elems' becomes the Nth member from the front of `Queue').
%
:- func queue.put_list_on_front(queue(T), list(T)) = queue(T).
-:- pred queue.put_list_on_front(queue(T)::in, list(T)::in, queue(T)::out)
+:- pred queue.put_list_on_front(list(T)::in, queue(T)::in, queue(T)::out)
is det.
- % `queue.get_from_back(Queue0, Elem, Queue)' removes `Elem' from
+ % `queue.get_from_back(Elem, Queue0, Queue)' removes `Elem' from
% the back of `Queue0', giving `Queue'.
%
-:- pred queue.get_from_back(queue(T)::in, T::out, queue(T)::out) is semidet.
+:- pred queue.get_from_back(T::out, queue(T)::in, queue(T)::out) is semidet.
%--------------------------------------------------------------------------%
%--------------------------------------------------------------------------%
@@ -133,12 +133,18 @@
% the names is that we generally get items off the off_list and put them
% on the on_list. We impose the extra constraint that the off_list field
% is empty if and only if the queue as a whole is empty.
+ %
:- type queue(T)
---> queue(
- on_list :: list(T),
- off_list :: list(T)
+ on_list :: list(T),
+ off_list :: list(T)
).
+%--------------------------------------------------------------------------%
+
+queue.init = Q :-
+ queue.init(Q).
+
queue.init(queue([], [])).
queue.equal(queue(OnA, OffA), queue(OnB, OffB)) :-
@@ -151,7 +157,10 @@
queue.is_full(_) :-
semidet_fail.
-queue.put(queue(On0, Off0), Elem, queue(On, Off)) :-
+queue.put(!.Q, T) = !:Q :-
+ queue.put(T, !Q).
+
+queue.put(Elem, queue(On0, Off0), queue(On, Off)) :-
(
Off0 = [],
On = On0,
@@ -162,7 +171,10 @@
Off = Off0
).
-queue.put_list(queue(On0, Off0), Xs, queue(On, Off)) :-
+queue.put_list(!.Q, Xs) = !:Q :-
+ queue.put_list(Xs, !Q).
+
+queue.put_list(Xs, queue(On0, Off0), queue(On, Off)) :-
(
Off0 = [],
On = On0,
@@ -181,7 +193,7 @@
queue.first(queue(_, [Elem | _]), Elem).
-queue.get(queue(On0, [Elem | Off0]), Elem, queue(On, Off)) :-
+queue.get(Elem, queue(On0, [Elem | Off0]), queue(On, Off)) :-
(
Off0 = [],
list.reverse(On0, Off),
@@ -192,18 +204,27 @@
Off = Off0
).
+queue.length(Q) = N :-
+ queue.length(Q, N).
+
queue.length(queue(On, Off), Length) :-
list.length(On, LengthOn),
list.length(Off, LengthOff),
Length = LengthOn + LengthOff.
+queue.list_to_queue(Xs) = Q :-
+ queue.list_to_queue(Xs, Q).
+
queue.list_to_queue(List, queue([], List)).
queue.from_list(List) = queue([], List).
queue.to_list(queue(On, Off)) = Off ++ list.reverse(On).
-queue.delete_all(queue(On0, Off0), Elem, queue(On, Off)) :-
+queue.delete_all(!.Q, T) = !:Q :-
+ queue.delete_all(T, !Q).
+
+queue.delete_all(Elem ,queue(On0, Off0), queue(On, Off)) :-
list.delete_all(On0, Elem, On1),
list.delete_all(Off0, Elem, Off1),
(
@@ -216,17 +237,17 @@
Off = Off1
).
-queue.put_on_front(queue(On, Off), Elem, queue(On, [Elem | Off])).
+queue.put_on_front(Elem, queue(On, Off), queue(On, [Elem | Off])).
-queue.put_on_front(Queue0, Elem) = Queue :-
- queue.put_on_front(Queue0, Elem, Queue).
+queue.put_on_front(!.Queue, Elem) = !:Queue :-
+ queue.put_on_front(Elem, !Queue).
-queue.put_list_on_front(queue(On, Off), Elems, queue(On, Elems ++ Off)).
+queue.put_list_on_front(Elems, queue(On, Off), queue(On, Elems ++ Off)).
-queue.put_list_on_front(Queue0, Elems) = Queue :-
- queue.put_list_on_front(Queue0, Elems, Queue).
+queue.put_list_on_front(!.Queue, Elems) = !:Queue :-
+ queue.put_list_on_front(Elems, !Queue).
-queue.get_from_back(queue(On0, Off0), Elem, queue(On, Off)) :-
+queue.get_from_back(Elem, queue(On0, Off0), queue(On, Off)) :-
(
% The On list is non-empty and the last element in the queue
% is the head of the On list.
@@ -251,24 +272,5 @@
).
%--------------------------------------------------------------------------%
+:- end_module queue.
%--------------------------------------------------------------------------%
-% Ralph Becket <rwab1 at cl.cam.ac.uk> 29/04/99
-% Function forms added.
-
-queue.init = Q :-
- queue.init(Q).
-
-queue.put(Q1, T) = Q2 :-
- queue.put(Q1, T, Q2).
-
-queue.put_list(Q1, Xs) = Q2 :-
- queue.put_list(Q1, Xs, Q2).
-
-queue.length(Q) = N :-
- queue.length(Q, N).
-
-queue.list_to_queue(Xs) = Q :-
- queue.list_to_queue(Xs, Q).
-
-queue.delete_all(Q1, T) = Q2 :-
- queue.delete_all(Q1, T, Q2).
Index: library/sveqvclass.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/sveqvclass.m,v
retrieving revision 1.7
diff -u -r1.7 sveqvclass.m
--- library/sveqvclass.m 6 Mar 2007 05:48:34 -0000 1.7
+++ library/sveqvclass.m 29 Apr 2011 13:25:11 -0000
@@ -62,17 +62,17 @@
:- implementation.
-sveqvclass.ensure_element(Element, EqvClass0, EqvClass) :-
- eqvclass.ensure_element(EqvClass0, Element, EqvClass).
+sveqvclass.ensure_element(Element, !EqvClass) :-
+ eqvclass.ensure_element(Element, !EqvClass).
-sveqvclass.new_element(Element, EqvClass0, EqvClass) :-
- eqvclass.new_element(EqvClass0, Element, EqvClass).
+sveqvclass.new_element(Element, !EqvClass) :-
+ eqvclass.new_element(Element, !EqvClass).
-sveqvclass.ensure_equivalence(Element1, Element2, EqvClass0, EqvClass) :-
- eqvclass.ensure_equivalence(EqvClass0, Element1, Element2, EqvClass).
+sveqvclass.ensure_equivalence(Element1, Element2, !EqvClass) :-
+ eqvclass.ensure_equivalence(Element1, Element2, !EqvClass).
-sveqvclass.new_equivalence(Element1, Element2, EqvClass0, EqvClass) :-
- eqvclass.new_equivalence(EqvClass0, Element1, Element2, EqvClass).
+sveqvclass.new_equivalence(Element1, Element2, !EqvClass) :-
+ eqvclass.new_equivalence(Element1, Element2, !EqvClass).
-sveqvclass.remove_equivalent_elements(X, EqvClass0, EqvClass) :-
- EqvClass = eqvclass.remove_equivalent_elements(EqvClass0, X).
+sveqvclass.remove_equivalent_elements(X, !EqvClass) :-
+ !:EqvClass = eqvclass.remove_equivalent_elements(!.EqvClass, X).
Index: library/svqueue.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/svqueue.m,v
retrieving revision 1.7
diff -u -r1.7 svqueue.m
--- library/svqueue.m 19 Apr 2006 05:17:58 -0000 1.7
+++ library/svqueue.m 29 Apr 2011 12:49:07 -0000
@@ -73,23 +73,23 @@
:- implementation.
-svqueue.put(Elem, Queue0, Queue) :-
- queue.put(Queue0, Elem, Queue).
+svqueue.put(Elem, !Queue) :-
+ queue.put(Elem, !Queue).
-svqueue.put_list(List, Queue0, Queue) :-
- queue.put_list(Queue0, List, Queue).
+svqueue.put_list(List, !Queue) :-
+ queue.put_list(List, !Queue).
-svqueue.get(Elem, Queue0, Queue) :-
- queue.get(Queue0, Elem, Queue).
+svqueue.get(Elem, !Queue) :-
+ queue.get(Elem, !Queue).
-svqueue.delete_all(Elem, Queue0, Queue) :-
- queue.delete_all(Queue0, Elem, Queue).
+svqueue.delete_all(Elem, !Queue) :-
+ queue.delete_all(Elem, !Queue).
-svqueue.put_on_front(Elem, Queue0, Queue) :-
- queue.put_on_front(Queue0, Elem, Queue).
+svqueue.put_on_front(Elem, !Queue) :-
+ queue.put_on_front(Elem, !Queue).
-svqueue.put_list_on_front(Elems, Queue0, Queue) :-
- queue.put_list_on_front(Queue0, Elems, Queue).
+svqueue.put_list_on_front(Elems, !Queue) :-
+ queue.put_list_on_front(Elems, !Queue).
-svqueue.get_from_back(Elem, Queue0, Queue) :-
- queue.get_from_back(Queue0, Elem, Queue).
+svqueue.get_from_back(Elem, !Queue) :-
+ queue.get_from_back(Elem, !Queue).
Index: tests/hard_coded/type_to_term_bug.m
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/hard_coded/type_to_term_bug.m,v
retrieving revision 1.1
diff -u -r1.1 type_to_term_bug.m
--- tests/hard_coded/type_to_term_bug.m 17 Feb 2000 06:38:34 -0000 1.1
+++ tests/hard_coded/type_to_term_bug.m 1 May 2011 13:39:59 -0000
@@ -13,7 +13,7 @@
main -->
{ queue__init(Q1) },
- { queue__put(Q1, 1, _Q2) },
+ { queue__put(1, Q1, _Q2) },
{ term__type_to_term(Q1, Term3) },
{ term__generic_term(Term3) },
write(Term3),
--------------------------------------------------------------------------
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