diff: extend support for `any' insts
Fergus Henderson
fjh at kryten.cs.mu.OZ.AU
Mon Sep 15 23:46:19 AEST 1997
Extend the support for `any' insts.
The compiler now assumes that the representation of `ground' or `bound'
insts is the same as for `any' insts, but in return it is possible to
mix these insts without the user having to provide explicit conversions
between different representations.
compiler/inst_match.m:
Allow `ground' or `bound' insts to be passed or returned where `any'
is expected.
compiler/inst_util.m:
Allow unification of `any' insts with `any' or `bound' or `ground'
insts.
compiler/unify_proc.m:
Use the `in_in' unification proc id (i.e. proc 0) for
unifications between `any' and `any' or `any' and `ground',
as well as for `ground' and `ground'. This should be safe,
I think, since the representation of `ground' and `any' is
required to be the same.
cvs diff: Diffing .
Index: inst_match.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/inst_match.m,v
retrieving revision 1.34
diff -u -u -r1.34 inst_match.m
--- 1.34 1997/08/23 20:32:58
+++ inst_match.m 1997/09/15 13:25:49
@@ -12,13 +12,10 @@
/*
The handling of `any' insts is not complete. (See also inst_util.m)
-It would be nice to allow `free', `bound' and `ground' to
-match `any', but right now we don't.
+It would be nice to allow `free' to match `any', but right now we don't.
The reason is that although the mode analysis would be pretty
straight-forward, generating the correct code is quite a bit trickier.
-In fact, much of the mode analysis code in this file is already
-done, just commented out with the remark "not yet".
-In addition, modes.m would have to be changed to handle the implicit
+modes.m would have to be changed to handle the implicit
conversions from `free'/`bound'/`ground' to `any' at
(1) procedure calls (this is just an extension of implied modes)
@@ -27,6 +24,11 @@
Since that is not yet done, we currently require the user to
insert explicit calls to initialize constraint variables.
+
+We do allow `bound' and `ground' to match `any', based on the
+assumption that `bound' and `ground' are represented in the same
+way as `any', i.e. that we use the type system rather than the
+mode system to distinguish between different representations.
*/
%-----------------------------------------------------------------------------%
@@ -286,11 +288,11 @@
inst_matches_initial_3(free, any(_), _, _).
*/
inst_matches_initial_3(free, free, _, _).
-/* not yet:
inst_matches_initial_3(bound(UniqA, ListA), any(UniqB), ModuleInfo, _) :-
unique_matches_initial(UniqA, UniqB),
- bound_inst_list_matches_uniq(ListA, UniqB, ModuleInfo).
-*/
+ bound_inst_list_matches_uniq(ListA, UniqB, ModuleInfo),
+ /* we do not yet allow `free' to match `any' */
+ bound_inst_list_is_ground_or_any(ListA, ModuleInfo).
inst_matches_initial_3(bound(_Uniq, _List), free, _, _).
inst_matches_initial_3(bound(UniqA, ListA), bound(UniqB, ListB), ModuleInfo,
Expansions) :-
@@ -308,10 +310,8 @@
Uniq = mostly_unique,
bound_inst_list_is_ground(List, ModuleInfo),
bound_inst_list_is_mostly_unique(List, ModuleInfo).
-/* not yet:
inst_matches_initial_3(ground(UniqA, _PredInst), any(UniqB), _, _) :-
unique_matches_initial(UniqA, UniqB).
-*/
inst_matches_initial_3(ground(_Uniq, _PredInst), free, _, _).
inst_matches_initial_3(ground(UniqA, _), bound(UniqB, List), ModuleInfo, _) :-
unique_matches_initial(UniqA, UniqB),
@@ -329,9 +329,7 @@
% I don't know what this should do.
% Abstract insts aren't really supported.
error("inst_matches_initial(ground, abstract_inst) == ??").
-/* not yet:
inst_matches_initial_3(abstract_inst(_,_), any(shared), _, _).
-*/
inst_matches_initial_3(abstract_inst(_,_), free, _, _).
inst_matches_initial_3(abstract_inst(Name, ArgsA), abstract_inst(Name, ArgsB),
ModuleInfo, Expansions) :-
@@ -519,12 +517,11 @@
inst_matches_final_3(free, any(_), _, _).
***/
inst_matches_final_3(free, free, _, _).
-/*
-not yet:
-inst_matches_final_3(bound(UniqA, ListA), any(UniqB), ModuleInfo, Expansions) :-
+inst_matches_final_3(bound(UniqA, ListA), any(UniqB), ModuleInfo, _) :-
unique_matches_final(UniqA, UniqB),
- bound_inst_list_matches_uniq(ListA, UniqB).
-*/
+ bound_inst_list_matches_uniq(ListA, UniqB, ModuleInfo),
+ /* we do not yet allow `free' to match `any' */
+ bound_inst_list_is_ground_or_any(ListA, ModuleInfo).
inst_matches_final_3(bound(UniqA, ListA), bound(UniqB, ListB), ModuleInfo,
Expansions) :-
unique_matches_final(UniqA, UniqB),
@@ -534,10 +531,8 @@
unique_matches_final(UniqA, UniqB),
bound_inst_list_is_ground(ListA, ModuleInfo),
bound_inst_list_matches_uniq(ListA, UniqB, ModuleInfo).
-/* not yet:
-inst_matches_final_3(ground(UniqA, _), any(UniqB), ModuleInfo, Expansions) :-
+inst_matches_final_3(ground(UniqA, _), any(UniqB), _ModuleInfo, _Expansions) :-
unique_matches_final(UniqA, UniqB).
-*/
inst_matches_final_3(ground(UniqA, _), bound(UniqB, ListB), ModuleInfo,
_Exps) :-
unique_matches_final(UniqA, UniqB),
@@ -552,9 +547,7 @@
maybe_pred_inst_matches_final(PredInstA, PredInstB,
ModuleInfo, Expansions),
unique_matches_final(UniqA, UniqB).
-/* not yet:
inst_matches_final_2(abstract_inst(_, _), any(shared), _, _).
-*/
inst_matches_final_3(abstract_inst(Name, ArgsA), abstract_inst(Name, ArgsB),
ModuleInfo, Expansions) :-
inst_list_matches_final(ArgsA, ArgsB, ModuleInfo, Expansions).
Index: inst_util.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/inst_util.m,v
retrieving revision 1.4
diff -u -u -r1.4 inst_util.m
--- 1.4 1997/09/14 09:24:24
+++ inst_util.m 1997/09/14 12:37:27
@@ -12,14 +12,10 @@
/*
The handling of `any' insts is not complete. (See also inst_match.m)
-Currently we don't allow any unifications with variables of mode `any'.
-The reason is that although the mode analysis would be pretty
-straight-forward, generating the correct code is quite a bit trickier.
-In fact, much of the mode analysis code in this file is already
-done, just commented out with the remark "not yet".
-The exception is abstract unification, which hasn't been done.
-In addition, modes.m would have to be changed to handle the implicit
-conversions from `free'/`bound'/`ground' to `any' at
+
+The major limitation is that we don't allow `free' to be passed
+where `any' is expected. To handle that, modes.m would have to be
+changed to handle the implicit conversions from `free' to `any' at
(1) procedure calls (this is just an extension of implied modes)
(2) the end of branched goals
@@ -27,6 +23,17 @@
Since that is not yet done, we currently require the user to
insert explicit calls to initialize constraint variables.
+
+Another limitation is that we don't allow any unifications between functors
+and variables of mode `any'; the reason for that is that I have no
+idea what code we should generate for them. Currently `any' insts
+are only used for abstract types, so the type system should prevent
+any unification between functors and variables of mode `any'.
+
+Another limitation is that currently code generation assumes that insts
+`bound', `ground', and `any' are all represented the same way.
+That works fine for the CLP(R) interface but might not be ideal
+in the general case.
*/
%-----------------------------------------------------------------------------%
@@ -207,7 +214,7 @@
abstractly_unify_inst_3(live, bound(UniqX, List0), any(UniqY), Real, M0,
bound(Uniq, List), Det, M) :-
- Real = fake_unify, % we do not yet support it for real_unifies
+ allow_unify_bound_any(Real),
unify_uniq(live, Real, semidet, UniqX, UniqY, Uniq),
make_any_bound_inst_list(List0, live, UniqY, Real, M0,
List, Det1, M),
@@ -305,7 +312,7 @@
abstractly_unify_inst_3(dead, bound(UniqX, List0), any(UniqY), Real, M0,
bound(Uniq, List), Det, M) :-
- Real = fake_unify, % we do not yet support it for real_unifies
+ allow_unify_bound_any(Real),
unify_uniq(dead, Real, semidet, UniqX, UniqY, Uniq),
make_any_bound_inst_list(List0, live, UniqY, Real, M0,
List, Det1, M),
@@ -344,7 +351,7 @@
abstractly_unify_inst_3(dead, ground(UniqX, yes(PredInst)), any(UniqY), Real, M,
ground(Uniq, yes(PredInst)), semidet, M) :-
- Real = fake_unify, % we do not yet support it for real_unifies
+ allow_unify_bound_any(Real),
unify_uniq(live, Real, semidet, UniqX, UniqY, Uniq).
abstractly_unify_inst_3(dead, ground(Uniq, yes(PredInst)), free, _Real, M,
@@ -830,7 +837,7 @@
make_any_inst(not_reached, _, _, _, M, not_reached, erroneous, M).
make_any_inst(any(Uniq0), IsLive, Uniq1, Real, M, any(Uniq),
semidet, M) :-
- Real = fake_unify, % not yet supported for real_unifies
+ allow_unify_bound_any(Real),
unify_uniq(IsLive, Real, semidet, Uniq0, Uniq1, Uniq).
make_any_inst(free, IsLive, Uniq0, Real, M, any(Uniq), det, M) :-
unify_uniq(IsLive, Real, det, unique, Uniq0, Uniq).
@@ -843,14 +850,14 @@
Any = typed_inst(T, unify_inst(IsLive, free, any(Uniq), Real)).
make_any_inst(bound(Uniq0, BoundInsts0), IsLive, Uniq1, Real, M0,
bound(Uniq, BoundInsts), Det, M) :-
- Real = fake_unify, % not yet supported for real_unifies
+ allow_unify_bound_any(Real),
unify_uniq(IsLive, Real, semidet, Uniq0, Uniq1, Uniq),
make_any_bound_inst_list(BoundInsts0, IsLive, Uniq1, Real, M0,
BoundInsts, Det1, M),
det_par_conjunction_detism(Det1, semidet, Det).
make_any_inst(ground(Uniq0, PredInst), IsLive, Uniq1, Real, M,
ground(Uniq, PredInst), semidet, M) :-
- Real = fake_unify, % not yet supported for real_unifies
+ allow_unify_bound_any(Real),
unify_uniq(IsLive, Real, semidet, Uniq0, Uniq1, Uniq).
make_any_inst(inst_var(_), _, _, _, _, _, _, _) :-
error("free inst var").
@@ -1168,6 +1175,16 @@
[Inst | Insts], ModuleInfo) :-
make_mostly_uniq_inst(Inst0, ModuleInfo0, Inst, ModuleInfo1),
make_mostly_uniq_inst_list(Insts0, ModuleInfo1, Insts, ModuleInfo).
+
+%-----------------------------------------------------------------------------%
+
+ % Should we allow unifications between bound (or ground) insts
+ % and `any' insts?
+ % Previously we only allowed this for fake_unifies,
+ % but now we allow it for real_unifies too.
+
+:- pred allow_unify_bound_any(unify_is_real::in) is det.
+allow_unify_bound_any(_) :- true.
%-----------------------------------------------------------------------------%
Index: unify_proc.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/unify_proc.m,v
retrieving revision 1.61
diff -u -u -r1.61 unify_proc.m
--- 1.61 1997/08/22 13:56:31
+++ unify_proc.m 1997/09/15 13:45:28
@@ -165,15 +165,17 @@
% Given the type, mode, and determinism of a unification, look up the
% mode number for the unification proc.
% We handle semidet unifications with mode (in, in) specially - they
- % are always mode zero. For unreachable unifications,
- % we also use mode zero.
+ % are always mode zero. Similarly for unifications of `any' insts.
+ % (It should be safe to use the `in, in' mode for any insts, since
+ % we assume that `ground' and `any' have the same representation.)
+ % For unreachable unifications, we also use mode zero.
unify_proc__search_mode_num(ModuleInfo, TypeId, UniMode, Determinism, ProcId) :-
UniMode = (XInitial - YInitial -> _Final),
(
Determinism = semidet,
- inst_is_ground(ModuleInfo, XInitial),
- inst_is_ground(ModuleInfo, YInitial)
+ inst_is_ground_or_any(ModuleInfo, XInitial),
+ inst_is_ground_or_any(ModuleInfo, YInitial)
->
hlds_pred__in_in_unification_proc_id(ProcId)
;
cvs diff: Diffing notes
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
More information about the developers
mailing list