[m-dev.] for review: alias branch improvements [2/2]
David Overton
dmo at cs.mu.OZ.AU
Mon Jul 26 16:12:19 AEST 1999
On Sun, Jul 25, 1999 at 12:28:52PM EST, Fergus Henderson wrote:
> On 23-Jul-1999, David Overton <dmo at cs.mu.OZ.AU> wrote:
> > +++ modecheck_call.m 1999/07/21 07:02:11
> ...
> > -:- pred compare_inst(inst, inst, maybe(inst), inst_table, match, module_info).
> > -:- mode compare_inst(in, in, in, in, out, in) is det.
> > +:- pred compare_inst(inst, inst, maybe(pair(inst, instmap)), inst_table,
> > + alias_map, alias_map, match, module_info).
> > +:- mode compare_inst(in, in, in, in, in, out, out, in) is det.
> >
> > -compare_inst(InstA, InstB, MaybeArgInst, InstTable, Result, ModuleInfo) :-
> > +compare_inst(InstA, InstB, MaybeArgInst, InstTable, AliasMap0, AliasMap,
> > + Result, ModuleInfo) :-
> > % inst_matches_initial(A,B) succeeds iff
> > % A specifies at least as much information
> > % and at least as much binding as B --
> > % with the exception that `any' matches_initial `free'
> > % and perhaps vice versa.
> > - instmap__init_reachable(InstMapA), % YYY
> > - instmap__init_reachable(InstMapB), % YYY
> > - instmap__init_reachable(MaybeInstMap), % YYY
> > + instmap__init_reachable(InstMapA),
> > + instmap__init_reachable(InstMapB),
> > + % Empty instmaps are ok here because InstA and InstB are
> > + % initial insts of procedures which will have no alias
> > + % substitutions on them.
>
> That strikes me as a fairly fragile assumption.
> Is this comment really true?
Almost. InstA and InstB may also be the final insts of a procedure.
However, the important point is that they come from the argument_modes
field of the proc_info.
>
> Is it an invariant that all initial insts of procedures will have no
> alias substitutions on them, or are you just assuming that this predicate
> won't be called for procedures whose initial insts have alias substitutions?
It is an invariant. It also applies to the final insts from the
proc_info argument_modes. There is not even an initial instmap stored
in the proc_info to allow any of these alias substitutions to be
stored.
>
> Either way, the invariant that this predicate will only be called for
> insts which are from a procedure's initial insts is an important part
> of the interface of this predicate and it should be documented with the
> predicate declaration, not just in the body of the predicate.
ok.
> You should check all of the callers of this predicate to make sure that
> they either ensure that it holds or document the same requirement of
> their callers.
Yes, I did this.
...
> > Index: prog_data.m
> > ===================================================================
> > RCS file: /home/mercury1/repository/mercury/compiler/prog_data.m,v
> > retrieving revision 1.24.2.19
> > diff -u -u -r1.24.2.19 prog_data.m
> > --- prog_data.m 1999/07/19 01:45:22 1.24.2.19
> > +++ prog_data.m 1999/07/21 05:01:17
> > @@ -23,9 +23,7 @@
> > % should be defined here, rather than in hlds*.m.
> >
> > :- import_module (inst).
> > -:- import_module hlds_data.
> > - % YYY hlds_data needed for inst_table definition. We should move the
> > - % definition of inst_table somewhere else.
> > +:- import_module inst_table.
>
> Why do prog_*.m need to import inst_table.m?
A couple of the types defined in prog_data.m contain inst_tables:
:- type types_and_modes
---> types_and_modes(inst_table, list(type_and_mode)).
:- type argument_modes ---> argument_modes(inst_table, list(mode)).
These are types that Andrew added to replace `list(type_and_mode)' and
`list(mode)' in places where an inst_table is also required for the
modes to make sense (i.e. most places). These two types are used in
several other type definitions in prog_data, e.g. for the `item' type.
I believe the reason for having inst_tables within the item type is
that it will be necessary when (and if) we allow users to specify
aliasing in mode declarations.
...
> --------------------
>
> Apart from that, it looks fine. Could you please send a relative
> diff when you've addressed those issues?
>
Here it is:
--- /home/pgrad/dmo/mer0/cmp/mercury/compiler/cvslog Mon Jul 26 11:29:15 1999
+++ ./cvslog Mon Jul 26 11:32:04 1999
@@ -61,6 +61,8 @@
on the inst_table as a whole in the same module.
It also means that prog_data no longer needs to import
hlds_data just to get the definition of the inst_table type.
+ The repetitiveness of the code for inst_table_ceate_sub has been
+ reduced by using type classes.
compiler/instmap.m:
Use other_inst_table instead of substitution_inst_table when
--- /home/pgrad/dmo/mer0/cmp/mercury/compiler/inst_match.m Mon Jul 26 11:05:07 1999
+++ ./inst_match.m Mon Jul 26 12:02:06 1999
@@ -359,7 +359,7 @@
**********/
;
inst_matches_aliasing(IgnoreAliasing, InstA, InstB,
- AliasMap0, AliasMap1),
+ InstMapA, AliasMap0, AliasMap1),
inst_expand(InstMapA, InstTable, ModuleInfo, InstA, InstA2),
inst_expand(InstMapB, InstTable, ModuleInfo, InstB, InstB2),
@@ -492,9 +492,12 @@
InstMapB, _InstTable, ModuleInfo, Expansions) :-
inst_table_create_sub(InstTableA, InstTableB, Sub, InstTable),
list__map(apply_inst_table_sub_mode(Sub), ModesB0, ModesB),
- map__init(AliasMap0),
+
+ % Initialise alias_maps for comparing aliases between the modes.
+ map__init(AliasMapA0),
+ map__init(AliasMapB0),
pred_inst_argmodes_matches(ModesA, InstMapA, ModesB, InstMapB,
- InstTable, ModuleInfo, Expansions, AliasMap0, AliasMap0).
+ InstTable, ModuleInfo, Expansions, AliasMapA0, AliasMapB0).
% pred_inst_matches_argmodes(ModesA, ModesB, ModuleInfo, Expansions):
% succeeds if the initial insts of ModesB specify at least as
@@ -630,19 +633,36 @@
%-----------------------------------------------------------------------------%
-:- pred inst_matches_aliasing(bool, inst, inst, alias_map, alias_map).
-:- mode inst_matches_aliasing(in, in, in, in, out) is semidet.
+ % inst_matches_aliasing(IgnoreAliasing, InstA, InstB,
+ % InstMapA, AliasMap0, AliasMap).
+ % If we are not ignoring aliasing, compare the aliasing of two
+ % insts with respect to the current alias_map and update the
+ % alias_map to include new aliasing information.
+ % InstA must be at least as aliased as InstB for the predicate
+ % to succeed.
-inst_matches_aliasing(yes, _, _, AliasMap, AliasMap).
-inst_matches_aliasing(no, InstA, InstB, AliasMap0, AliasMap) :-
+:- pred inst_matches_aliasing(bool, inst, inst, instmap, alias_map, alias_map).
+:- mode inst_matches_aliasing(in, in, in, in, in, out) is semidet.
+
+inst_matches_aliasing(yes, _, _, _, AliasMap, AliasMap).
+inst_matches_aliasing(no, InstA, InstB, InstMapA, AliasMap0, AliasMap) :-
( InstB = alias(IKB) ->
( map__search(AliasMap0, IKB, MaybeIK) ->
- MaybeIK = yes(IKA),
+ % This inst_key has been seen before.
+ % Check whether InstA has a matching alias.
+ MaybeIK = yes(PrevIK),
InstA = alias(IKA),
+ instmap__inst_keys_are_equivalent(PrevIK, InstMapA,
+ IKA, InstMapA),
AliasMap = AliasMap0
; InstA = alias(IKA) ->
+ % Insert the new pair of corresponding inst_keys
+ % into the alias_map.
map__det_insert(AliasMap0, IKB, yes(IKA), AliasMap)
;
+ % Record that the new inst_key IKB has no corresponding
+ % inst_key in InstA. If alias(IKB) occurs a second
+ % time, the predicate will fail.
map__det_insert(AliasMap0, IKB, no, AliasMap)
)
;
@@ -702,7 +722,7 @@
AliasMap = AliasMap0
;
inst_matches_aliasing(IgnoreAliasing, InstA, InstB,
- AliasMap0, AliasMap1),
+ InstMapA, AliasMap0, AliasMap1),
inst_expand(InstMapA, InstTable, ModuleInfo, InstA, InstA2),
inst_expand(InstMapB, InstTable, ModuleInfo, InstB, InstB2),
--- /home/pgrad/dmo/mer0/cmp/mercury/compiler/inst_table.m Mon Jul 26 11:05:07 1999
+++ ./inst_table.m Mon Jul 26 12:09:07 1999
@@ -365,39 +365,6 @@
SharedInstTable, MostlyUniqInstTable, ClobberedInstTable,
OtherInstTable, IKT, InstTable).
-:- pred maybe_inst_apply_sub(inst_table_sub, maybe_inst, maybe_inst).
-:- mode maybe_inst_apply_sub(in, in, out) is det.
-
-maybe_inst_apply_sub(_, unknown, unknown).
-maybe_inst_apply_sub(Sub, known(I0), known(I)) :-
- inst_apply_inst_table_sub(Sub, I0, I).
-
-:- pred maybe_inst_det_apply_sub(inst_table_sub, maybe_inst_det,
- maybe_inst_det).
-:- mode maybe_inst_det_apply_sub(in, in, out) is det.
-
-maybe_inst_det_apply_sub(_, unknown, unknown).
-maybe_inst_det_apply_sub(Sub, known(I0, D), known(I, D)) :-
- inst_apply_inst_table_sub(Sub, I0, I).
-
-:- pred merge_inst_pair_apply_sub(inst_table_sub, merge_inst_pair,
- merge_inst_pair).
-:- mode merge_inst_pair_apply_sub(in, in, out) is det.
-
-merge_inst_pair_apply_sub(Sub, Pair0, Pair) :-
- Pair0 = merge_inst_pair(IsLive, IA0, IB0),
- inst_apply_inst_table_sub(Sub, IA0, IA),
- inst_apply_inst_table_sub(Sub, IB0, IB),
- Pair = merge_inst_pair(IsLive, IA, IB).
-
-:- pred other_inst_apply_sub(inst_table_sub, other_inst, other_inst).
-:- mode other_inst_apply_sub(in, in, out) is det.
-
-other_inst_apply_sub(Sub, other_inst(Id0, Name0), other_inst(Id, Name)) :-
- Sub = inst_table_sub(_IKSub, IdSub),
- Id = other_inst_id_apply_sub(IdSub, Id0),
- inst_name_apply_sub(Sub, Name0, Name).
-
:- pred map_apply_sub(inst_table_sub, map(K, V), map(K, V), map(K, V))
<= (inst_table_entry(K), inst_table_entry(V)).
:- mode map_apply_sub(in, in, in, out) is det.
@@ -493,3 +460,37 @@
inst_apply_inst_table_sub(Sub, abstract_inst(SymName, Insts0),
abstract_inst(SymName, Insts)) :-
list__map(inst_apply_inst_table_sub(Sub), Insts0, Insts).
+
+:- pred maybe_inst_apply_sub(inst_table_sub, maybe_inst, maybe_inst).
+:- mode maybe_inst_apply_sub(in, in, out) is det.
+
+maybe_inst_apply_sub(_, unknown, unknown).
+maybe_inst_apply_sub(Sub, known(I0), known(I)) :-
+ inst_apply_inst_table_sub(Sub, I0, I).
+
+:- pred maybe_inst_det_apply_sub(inst_table_sub, maybe_inst_det,
+ maybe_inst_det).
+:- mode maybe_inst_det_apply_sub(in, in, out) is det.
+
+maybe_inst_det_apply_sub(_, unknown, unknown).
+maybe_inst_det_apply_sub(Sub, known(I0, D), known(I, D)) :-
+ inst_apply_inst_table_sub(Sub, I0, I).
+
+:- pred merge_inst_pair_apply_sub(inst_table_sub, merge_inst_pair,
+ merge_inst_pair).
+:- mode merge_inst_pair_apply_sub(in, in, out) is det.
+
+merge_inst_pair_apply_sub(Sub, Pair0, Pair) :-
+ Pair0 = merge_inst_pair(IsLive, IA0, IB0),
+ inst_apply_inst_table_sub(Sub, IA0, IA),
+ inst_apply_inst_table_sub(Sub, IB0, IB),
+ Pair = merge_inst_pair(IsLive, IA, IB).
+
+:- pred other_inst_apply_sub(inst_table_sub, other_inst, other_inst).
+:- mode other_inst_apply_sub(in, in, out) is det.
+
+other_inst_apply_sub(Sub, other_inst(Id0, Name0), other_inst(Id, Name)) :-
+ Sub = inst_table_sub(_IKSub, IdSub),
+ Id = other_inst_id_apply_sub(IdSub, Id0),
+ inst_name_apply_sub(Sub, Name0, Name).
+
--- /home/pgrad/dmo/mer0/cmp/mercury/compiler/modecheck_call.m Mon Jul 26 11:05:11 1999
+++ ./modecheck_call.m Mon Jul 26 13:20:07 1999
@@ -781,6 +781,16 @@
combine_results(CompareInsts, CompareLives, Compare0),
prioritized_combine_results(Compare0, CompareDet, Compare).
+ % compare_inst_list(InstsA, InstsB, ArgInsts, InstTable, Result,
+ % ModuleInfo)
+ % Compare two lists of insts. InstsA and InstsB should
+ % not depend on any instmap alias substitutions. Also,
+ % InstsA and InstsB should not share any common inst_keys.
+ % These preconditions are guaranteed if the inst lists are
+ % the argument insts of two procedures (with an
+ % appropriate application of inst_table_create_sub to
+ % rename apart the inst_keys of the two procedures).
+
:- pred compare_inst_list(list(inst), list(inst),
maybe(pair(list(inst), instmap)), inst_table, match, module_info).
:- mode compare_inst_list(in, in, in, in, out, in) is det.
@@ -889,6 +899,15 @@
% prefer ground to free (i.e. prefer in to out)
% prefer ground to any (e.g. prefer in to in(any))
% prefer any to free (e.g. prefer any->ground to out)
+ %
+ % This predicate is designed to be called from compare_inst_list
+ % which is used for comparing argument insts of two procedures.
+ % It assumes that InstA and InstB do not depend on any instmap
+ % alias substitutions. InstA and InstB are also required not to
+ % share any inst_keys. It also assumes that AliasMap0 will be
+ % initialised before the first call to compare_inst and the
+ % alias_map will be threaded through all calls to compare_inst
+ % for the list of insts being compared.
:- pred compare_inst(inst, inst, maybe(pair(inst, instmap)), inst_table,
alias_map, alias_map, match, module_info).
@@ -904,8 +923,8 @@
instmap__init_reachable(InstMapA),
instmap__init_reachable(InstMapB),
% Empty instmaps are ok here because InstA and InstB are
- % initial insts of procedures which will have no alias
- % substitutions on them.
+ % assumed to be insts which have no instmap alias substitutions
+ % on them.
(
inst_matches_initial(InstA, InstMapA, InstB, InstMapB,
InstTable, ModuleInfo, AliasMap0, AliasMap1)
--- /home/pgrad/dmo/mer0/cmp/mercury/compiler/pd_term.m Mon Jul 26 11:05:12 1999
+++ ./pd_term.m Mon Jul 26 12:19:26 1999
@@ -1,5 +1,5 @@
%-----------------------------------------------------------------------------%
-% Copyright (C) 1999 University of Melbourne.
+% Copyright (C) 1998-1999 University of Melbourne.
% This file may only be copied under the terms of the GNU General
% Public License - see the file COPYING in the Mercury distribution.
%-----------------------------------------------------------------------------%
--- /home/pgrad/dmo/mer0/cmp/mercury/compiler/prog_data.m Mon Jul 26 11:05:13 1999
+++ ./prog_data.m Mon Jul 26 13:37:07 1999
@@ -729,17 +729,32 @@
; typed_inst(type, inst_name)
; other_inst(other_inst_id, inst_name).
+ % other_inst_id is used for distinguishing between inst_names
+ % with functor other_inst.
:- type other_inst_id.
+ % other_inst_id_sub describes the substitution that needs to be applied
+ % to other_inst_ids from one procedure to allow them to be compared
+ % to other_inst_ids in another procedure.
+
:- type other_inst_id_sub.
+ % Initialise the other_inst_id.
+
:- func init_other_inst_id = other_inst_id.
+ % Get the next other_inst_id.
+
:- func inc_other_inst_id(other_inst_id) = other_inst_id.
+ % Apply an other_inst_is_sub substitution to an other_inst_id.
+
:- func other_inst_id_apply_sub(other_inst_id_sub, other_inst_id)
= other_inst_id.
+ % Create an other_inst_id_sub to be used for comparing other_inst_ids
+ % from different procedures.
+
:- func other_inst_id_create_sub(other_inst_id) = other_inst_id_sub.
% Note: `is_live' records liveness in the sense used by
--- /home/pgrad/dmo/mer0/cmp/mercury/compiler/unify_proc.m Mon Jul 26 11:05:20 1999
+++ ./unify_proc.m Mon Jul 26 14:59:33 1999
@@ -131,7 +131,7 @@
% (mode number) of the unification procedure which corresponds to
% that mode.
-:- type unify_req_map == assoc_list(unify_proc_id, proc_id).
+:- type unify_req_map == map(type_id, assoc_list(unify_proc_id, proc_id)).
:- type req_queue == queue(pred_proc_id).
@@ -146,7 +146,7 @@
%-----------------------------------------------------------------------------%
unify_proc__init_requests(Requests) :-
- UnifyReqMap = [],
+ map__init(UnifyReqMap),
queue__init(ReqQueue),
Requests = proc_requests(UnifyReqMap, ReqQueue).
@@ -205,7 +205,7 @@
unify_proc__search_mode_num(InstMapBefore, ModuleInfo, UnifyId, Determinism,
ProcId) :-
- UnifyId = unify_proc_id(_, XInitial, YInitial, InstTable),
+ UnifyId = unify_proc_id(TypeId, XInitial, YInitial, InstTable),
(
Determinism = semidet,
inst_is_ground_or_any(XInitial, InstMapBefore,
@@ -225,12 +225,13 @@
;
module_info_get_proc_requests(ModuleInfo, Requests),
unify_proc__get_unify_req_map(Requests, UnifyReqMap),
- unify_proc__search_mode_num_2(UnifyReqMap, UnifyId,
+ map__search(UnifyReqMap, TypeId, UnifyProcs),
+ unify_proc__search_mode_num_2(UnifyProcs, UnifyId,
InstMapBefore, ModuleInfo, ProcId)
).
-:- pred unify_proc__search_mode_num_2(unify_req_map, unify_proc_id,
- instmap, module_info, proc_id).
+:- pred unify_proc__search_mode_num_2(assoc_list(unify_proc_id, proc_id),
+ unify_proc_id, instmap, module_info, proc_id).
:- mode unify_proc__search_mode_num_2(in, in, in, in, out) is semidet.
unify_proc__search_mode_num_2([UnifyIdA - ProcId0 | Rest], UnifyIdB,
@@ -321,7 +322,12 @@
%
module_info_get_proc_requests(ModuleInfo3, Requests0),
unify_proc__get_unify_req_map(Requests0, UnifyReqMap0),
- UnifyReqMap = [UnifyId - ProcId | UnifyReqMap0],
+ ( map__search(UnifyReqMap0, TypeId, UnifyProcs0) ->
+ UnifyProcs = [UnifyId - ProcId | UnifyProcs0]
+ ;
+ UnifyProcs = [UnifyId - ProcId]
+ ),
+ map__set(UnifyReqMap0, TypeId, UnifyProcs, UnifyReqMap),
unify_proc__set_unify_req_map(Requests0, UnifyReqMap, Requests),
module_info_set_proc_requests(ModuleInfo3, Requests,
ModuleInfo)
@@ -372,6 +378,20 @@
%-----------------------------------------------------------------------------%
+ % normalise_unify_id removes all unnecessary aliases and inst_table
+ % entries from the unify_proc_id.
+ % Aliases are retained only between corresponding nodes in the
+ % inst trees of the two arguments. Such aliases allow us to
+ % produce more efficient code for the unification procedure
+ % since, if we know that two corresponding nodes are already
+ % aliased, we don't need to produce code to unify them.
+ % (In such cases the unification goal will be replaced by conj([])
+ % during mode checking by categorize_unify_var_var).
+
+ % normalise_unify_id also removes any instmap alias substitution
+ % dependencies from the insts. This is important since these are
+ % not allowed in the argument insts of a procedure.
+
:- pred normalise_unify_id(instmap, module_info, unify_proc_id, unify_proc_id).
:- mode normalise_unify_id(in, in, in, out) is det.
@@ -392,10 +412,10 @@
normalise_unify_insts(InstMap, ModuleInfo, OrigInstTable, InstL0, InstL,
InstR0, InstR, InstTable0, InstTable) :-
( ( InstL0 = defined_inst(_) ; InstR0 = defined_inst(_) ) ->
- inst_remove_aliases(InstMap, ModuleInfo, OrigInstTable,
- InstL0, InstL, InstTable0, InstTable1),
- inst_remove_aliases(InstMap, ModuleInfo, OrigInstTable,
- InstR0, InstR, InstTable1, InstTable)
+ inst_remove_aliases(InstL0, InstMap, ModuleInfo, OrigInstTable,
+ InstL, InstTable0, InstTable1),
+ inst_remove_aliases(InstR0, InstMap, ModuleInfo, OrigInstTable,
+ InstR, InstTable1, InstTable)
;
normalise_unify_insts_2(InstMap, ModuleInfo, OrigInstTable,
InstL0, InstL, InstR0, InstR, InstTable0, InstTable)
@@ -411,13 +431,15 @@
(
InstL0 = alias(IKL)
->
- ( InstR0 = alias(IKR) ->
+ (
+ InstR0 = alias(IKR)
+ ->
(
instmap__inst_keys_are_equivalent(IKL, InstMap,
IKR, InstMap)
->
- inst_remove_aliases(InstMap, ModuleInfo,
- OrigInstTable, alias(IKL), Inst,
+ inst_remove_aliases(alias(IKL), InstMap,
+ ModuleInfo, OrigInstTable, Inst,
InstTable0, InstTable1),
inst_table_get_inst_key_table(InstTable1, IKT0),
inst_key_table_add(IKT0, Inst, IK, IKT),
@@ -454,7 +476,9 @@
;
InstL0 = bound(UniqL, BoundInstsL0)
->
- ( InstR0 = bound(UniqR, BoundInstsR0) ->
+ (
+ InstR0 = bound(UniqR, BoundInstsR0)
+ ->
normalise_unify_bound_insts(InstMap, ModuleInfo,
OrigInstTable, BoundInstsL0, BoundInstsL,
BoundInstsR0, BoundInstsR,
@@ -462,22 +486,21 @@
InstL = bound(UniqL, BoundInstsL),
InstR = bound(UniqR, BoundInstsR)
;
- bound_insts_remove_aliases(InstMap, ModuleInfo,
- OrigInstTable, BoundInstsL0, BoundInstsL,
+ bound_insts_remove_aliases(BoundInstsL0, InstMap,
+ ModuleInfo, OrigInstTable, BoundInstsL,
InstTable0, InstTable1),
InstL = bound(UniqL, BoundInstsL),
- inst_remove_aliases(InstMap, ModuleInfo,
- OrigInstTable, InstR0, InstR, InstTable1,
- InstTable)
+ inst_remove_aliases(InstR0, InstMap, ModuleInfo,
+ OrigInstTable, InstR, InstTable1, InstTable)
)
;
InstR0 = bound(UniqR, BoundInstsR0)
->
- bound_insts_remove_aliases(InstMap, ModuleInfo, OrigInstTable,
- BoundInstsR0, BoundInstsR, InstTable0, InstTable1),
+ bound_insts_remove_aliases(BoundInstsR0, InstMap, ModuleInfo,
+ OrigInstTable, BoundInstsR, InstTable0, InstTable1),
InstR = bound(UniqR, BoundInstsR),
- inst_remove_aliases(InstMap, ModuleInfo, OrigInstTable,
- InstL0, InstL, InstTable1, InstTable)
+ inst_remove_aliases(InstL0, InstMap, ModuleInfo, OrigInstTable,
+ InstL, InstTable1, InstTable)
;
InstL0 = abstract_inst(Name, InstsL0),
InstR0 = abstract_inst(Name, InstsR0),
@@ -489,10 +512,10 @@
InstR = abstract_inst(Name, InstsR),
InstTable = InstTable1
;
- inst_remove_aliases(InstMap, ModuleInfo, OrigInstTable,
- InstL0, InstL, InstTable0, InstTable1),
- inst_remove_aliases(InstMap, ModuleInfo, OrigInstTable,
- InstR0, InstR, InstTable1, InstTable)
+ inst_remove_aliases(InstL0, InstMap, ModuleInfo, OrigInstTable,
+ InstL, InstTable0, InstTable1),
+ inst_remove_aliases(InstR0, InstMap, ModuleInfo, OrigInstTable,
+ InstR, InstTable1, InstTable)
).
% normalise_unify_insts fails iff the lists are different lengths.
@@ -518,11 +541,11 @@
normalise_unify_bound_insts(InstMap, ModuleInfo, OrigInstTable, [], [],
BI0, BI) -->
{ BI0 = [_|_] },
- bound_insts_remove_aliases(InstMap, ModuleInfo, OrigInstTable, BI0, BI).
+ bound_insts_remove_aliases(BI0, InstMap, ModuleInfo, OrigInstTable, BI).
normalise_unify_bound_insts(InstMap, ModuleInfo, OrigInstTable, BI0, BI,
[], []) -->
{ BI0 = [_|_] },
- bound_insts_remove_aliases(InstMap, ModuleInfo, OrigInstTable, BI0, BI).
+ bound_insts_remove_aliases(BI0, InstMap, ModuleInfo, OrigInstTable, BI).
normalise_unify_bound_insts(InstMap, ModuleInfo, OrigInstTable,
[BL0 | BLs0], BLs, [BR0 | BRs0], BRs) -->
{ BL0 = functor(ConsIdL, ILs0) },
@@ -537,10 +560,10 @@
{ ILs = ILs1 },
{ IRs = IRs1 }
;
- insts_remove_aliases(InstMap, ModuleInfo, OrigInstTable,
- ILs0, ILs),
- insts_remove_aliases(InstMap, ModuleInfo, OrigInstTable,
- IRs0, IRs)
+ insts_remove_aliases(ILs0, InstMap, ModuleInfo,
+ OrigInstTable, ILs),
+ insts_remove_aliases(IRs0, InstMap, ModuleInfo,
+ OrigInstTable, IRs)
),
{ BLs = [functor(ConsIdL, ILs) | BLs1] },
{ BRs = [functor(ConsIdR, IRs) | BRs1] },
@@ -548,15 +571,15 @@
BLs0, BLs1, BRs0, BRs1)
;
{ Comp = (<) },
- insts_remove_aliases(InstMap, ModuleInfo, OrigInstTable,
- ILs0, ILs),
+ insts_remove_aliases(ILs0, InstMap, ModuleInfo, OrigInstTable,
+ ILs),
{ BLs = [functor(ConsIdL, ILs) | BLs1] },
normalise_unify_bound_insts(InstMap, ModuleInfo, OrigInstTable,
BLs0, BLs1, [BR0 | BRs0], BRs)
;
{ Comp = (>) },
- insts_remove_aliases(InstMap, ModuleInfo, OrigInstTable,
- IRs0, IRs),
+ insts_remove_aliases(IRs0, InstMap, ModuleInfo, OrigInstTable,
+ IRs),
{ BRs = [functor(ConsIdR, IRs) | BRs1] },
normalise_unify_bound_insts(InstMap, ModuleInfo, OrigInstTable,
[BL0 | BLs0], BLs, BRs0, BRs1)
@@ -565,34 +588,34 @@
%-----------------------------------------------------------------------------%
-:- pred inst_remove_aliases(instmap, module_info, inst_table, inst, inst,
+:- pred inst_remove_aliases(inst, instmap, module_info, inst_table, inst,
inst_table, inst_table).
:- mode inst_remove_aliases(in, in, in, in, out, in, out) is det.
-inst_remove_aliases(_, _, _, any(U), any(U), IT, IT).
-inst_remove_aliases(_, _, _, free(A), free(A), IT, IT).
-inst_remove_aliases(_, _, _, free(A, T), free(A, T), IT, IT).
-inst_remove_aliases(_, _, _, ground(U, P), ground(U, P), IT, IT).
-inst_remove_aliases(_, _, _, not_reached, not_reached, IT, IT).
-inst_remove_aliases(_, _, _, inst_var(V), inst_var(V), IT, IT).
-inst_remove_aliases(InstMap, ModuleInfo, OrigInstTable, alias(IK), Inst,
+inst_remove_aliases(any(U), _, _, _, any(U), IT, IT).
+inst_remove_aliases(free(A), _, _, _, free(A), IT, IT).
+inst_remove_aliases(free(A, T), _, _, _, free(A, T), IT, IT).
+inst_remove_aliases(ground(U, P), _, _, _, ground(U, P), IT, IT).
+inst_remove_aliases(not_reached, _, _, _, not_reached, IT, IT).
+inst_remove_aliases(inst_var(V), _, _, _, inst_var(V), IT, IT).
+inst_remove_aliases(alias(IK), InstMap, ModuleInfo, OrigInstTable, Inst,
InstTable0, InstTable) :-
inst_table_get_inst_key_table(OrigInstTable, IKT),
instmap__inst_key_table_lookup(InstMap, IKT, IK, Inst0),
- inst_remove_aliases(InstMap, ModuleInfo, OrigInstTable, Inst0, Inst,
+ inst_remove_aliases(Inst0, InstMap, ModuleInfo, OrigInstTable, Inst,
InstTable0, InstTable).
-inst_remove_aliases(InstMap, ModuleInfo, OrigInstTable,
- abstract_inst(Name, Insts0), abstract_inst(Name, Insts),
+inst_remove_aliases(abstract_inst(Name, Insts0), InstMap, ModuleInfo,
+ OrigInstTable, abstract_inst(Name, Insts),
InstTable0, InstTable) :-
- insts_remove_aliases(InstMap, ModuleInfo, OrigInstTable, Insts0, Insts,
+ insts_remove_aliases(Insts0, InstMap, ModuleInfo, OrigInstTable, Insts,
InstTable0, InstTable).
-inst_remove_aliases(InstMap, ModuleInfo, OrigInstTable, bound(U, BoundInsts0),
+inst_remove_aliases(bound(U, BoundInsts0), InstMap, ModuleInfo, OrigInstTable,
bound(U, BoundInsts), InstTable0, InstTable) :-
- bound_insts_remove_aliases(InstMap, ModuleInfo, OrigInstTable,
- BoundInsts0, BoundInsts, InstTable0, InstTable).
-inst_remove_aliases(InstMap, ModuleInfo, OrigInstTable,
- defined_inst(InstName0), Inst, InstTable0, InstTable) :-
+ bound_insts_remove_aliases(BoundInsts0, InstMap, ModuleInfo,
+ OrigInstTable, BoundInsts, InstTable0, InstTable).
+inst_remove_aliases(defined_inst(InstName0), InstMap, ModuleInfo,
+ OrigInstTable, Inst, InstTable0, InstTable) :-
inst_table_get_other_insts(InstTable0, OtherInsts0),
other_inst_table_mark_inst_name(OtherInsts0, InstName0, InstName),
( other_inst_table_search(OtherInsts0, InstName0, MaybeInst) ->
@@ -610,8 +633,8 @@
inst_lookup(OrigInstTable, ModuleInfo, InstName0, Inst0),
inst_expand_defined_inst(OrigInstTable, ModuleInfo, Inst0,
Inst1),
- inst_remove_aliases(InstMap, ModuleInfo, OrigInstTable,
- Inst1, Inst2, InstTable1, InstTable2),
+ inst_remove_aliases(Inst1, InstMap, ModuleInfo, OrigInstTable,
+ Inst2, InstTable1, InstTable2),
inst_table_get_other_insts(InstTable2, OtherInsts2),
other_inst_table_set(OtherInsts2, InstName0, known(Inst2),
@@ -635,25 +658,25 @@
Inst = Inst2
).
-:- pred insts_remove_aliases(instmap, module_info, inst_table,
- list(inst), list(inst), inst_table, inst_table).
+:- pred insts_remove_aliases(list(inst), instmap, module_info, inst_table,
+ list(inst), inst_table, inst_table).
:- mode insts_remove_aliases(in, in, in, in, out, in, out) is det.
-insts_remove_aliases(_, _, _, [], []) --> [].
-insts_remove_aliases(InstMap, ModuleInfo, OrigInstTable, [I0 | Is0], [I | Is])
+insts_remove_aliases([], _, _, _, []) --> [].
+insts_remove_aliases([I0 | Is0], InstMap, ModuleInfo, OrigInstTable, [I | Is])
-->
- inst_remove_aliases(InstMap, ModuleInfo, OrigInstTable, I0, I),
- insts_remove_aliases(InstMap, ModuleInfo, OrigInstTable, Is0, Is).
+ inst_remove_aliases(I0, InstMap, ModuleInfo, OrigInstTable, I),
+ insts_remove_aliases(Is0, InstMap, ModuleInfo, OrigInstTable, Is).
-:- pred bound_insts_remove_aliases(instmap, module_info, inst_table,
- list(bound_inst), list(bound_inst), inst_table, inst_table).
+:- pred bound_insts_remove_aliases(list(bound_inst), instmap, module_info,
+ inst_table, list(bound_inst), inst_table, inst_table).
:- mode bound_insts_remove_aliases(in, in, in, in, out, in, out) is det.
-bound_insts_remove_aliases(_, _, _, [], []) --> [].
-bound_insts_remove_aliases(InstMap, ModuleInfo, OrigInstTable,
- [functor(C, Is0) | Bs0], [functor(C, Is) | Bs]) -->
- insts_remove_aliases(InstMap, ModuleInfo, OrigInstTable, Is0, Is),
- bound_insts_remove_aliases(InstMap, ModuleInfo, OrigInstTable, Bs0, Bs).
+bound_insts_remove_aliases([], _, _, _, []) --> [].
+bound_insts_remove_aliases([functor(C, Is0) | Bs0], InstMap, ModuleInfo,
+ OrigInstTable, [functor(C, Is) | Bs]) -->
+ insts_remove_aliases(Is0, InstMap, ModuleInfo, OrigInstTable, Is),
+ bound_insts_remove_aliases(Bs0, InstMap, ModuleInfo, OrigInstTable, Bs).
%-----------------------------------------------------------------------------%
--
David Overton Department of Computer Science & Software Engineering
MEngSc Student The University of Melbourne, Australia
+61 3 9344 9159 http://www.cs.mu.oz.au/~dmo
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list