[m-rev.] diff: allow var-functor unifications for vars with inst `any'.

David Overton dmo at cs.mu.OZ.AU
Mon May 13 16:19:16 AEST 2002


On Thu, May 09, 2002 at 07:49:24PM +1000, Fergus Henderson wrote:
> On 09-May-2002, David Overton <dmo at cs.mu.OZ.AU> wrote:
> > Allow var-functor unifications where the variable has inst `any'.
> >
> > compiler/inst_util.m:
> > 	Handle `any' insts in abstractly_unify_inst_functor.
> 
> I don't think this is sufficient, since handling var-functor unifications
> where the variable has inst `any' would require not just changes to the
> mode analysis algorithm, but also changes to code generation, since the
> current code generator doesn't know how to implement such unifications.
> 
> Unless you are assuming that any concrete type which has inst `any' must
> actually be ground... I guess that could work, but if so, that assumption
> should be clearly documented somewhere, including in particular the
> places in mode analysis and/or code generation which rely on it.

This assumption is documented at the top of inst_util.m, however I have
modified the comments there as shown below.

> 
> > tests/valid/Mmakefile:
> > tests/valid/any_functor_unify.m:
> > 	Add a test case.
> 
> I would like to see a more substantial test, that was actually executed
> (i.e. in the hard_coded or general directory, not in the valid directory),
> so that it tests that the code generation is correct.
> By more substantial I mean you should test several cases -- e.g.
> discriminated union types, enumeration types, and atomic types
> such as `int', not just no-tag types.

Done

Estimated hours taken: 0.5
Branches: main

compiler/inst_util.m:
	Modify comments at the top of the file to reflect that any-functor
	unifications are now allowed, but that they assume that `any' has the
	same representation as `ground'.

tests/hard_coded/Mmakefle:
tests/hard_coded/any_functor_unify.m:
tests/hard_coded/any_functor_unify.exp:
	Add a test case for testing unifications between functors and variables
	with inst `any'.


Index: compiler/inst_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/inst_util.m,v
retrieving revision 1.21
diff -u -r1.21 inst_util.m
--- compiler/inst_util.m	9 May 2002 05:00:53 -0000	1.21
+++ compiler/inst_util.m	13 May 2002 06:13:59 -0000
@@ -24,16 +24,11 @@
 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.
+in the general case.  In particular, this may cause problems for
+unifications between variables and functors.
 */
 
 %-----------------------------------------------------------------------------%
Index: tests/hard_coded/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/Mmakefile,v
retrieving revision 1.151
diff -u -r1.151 Mmakefile
--- tests/hard_coded/Mmakefile	7 May 2002 11:02:42 -0000	1.151
+++ tests/hard_coded/Mmakefile	13 May 2002 06:13:59 -0000
@@ -10,6 +10,7 @@
 ORDINARY_PROGS=	\
 	address_of_builtins \
 	agg \
+	any_functor_unify \
 	bidirectional \
 	bigtest \
 	boyer \
Index: tests/hard_coded/any_functor_unify.exp
===================================================================
RCS file: tests/hard_coded/any_functor_unify.exp
diff -N tests/hard_coded/any_functor_unify.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/any_functor_unify.exp	13 May 2002 06:13:59 -0000
@@ -0,0 +1,6 @@
+yes
+no
+yes
+no
+yes
+no
Index: tests/hard_coded/any_functor_unify.m
===================================================================
RCS file: tests/hard_coded/any_functor_unify.m
diff -N tests/hard_coded/any_functor_unify.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/any_functor_unify.m	13 May 2002 06:13:59 -0000
@@ -0,0 +1,50 @@
+:- module any_functor_unify.
+:- interface.
+
+:- import_module io.
+
+:- pred main(io::di, io::uo) is det.
+
+:- implementation.
+
+:- type dutype ---> f(int) ; g(float).
+:- type enumtype ---> a ; b ; c.
+
+main -->
+	( { p(f(42)) } ->	yes ; no ),
+	( { p(g(100.0)) } ->	yes ; no ),
+	( { q(a) } ->		yes ; no ),
+	( { q(c) } ->		yes ; no ),
+	( { r(42) } ->		yes ; no ),
+	( { r(101) } ->		yes ; no ).
+
+:- pred p(dutype).
+:- mode p(in(any)) is semidet.
+
+:- pragma no_inline(p/1).
+
+p(X) :- X = f(_).
+
+:- pred q(enumtype).
+:- mode q(in(any)) is semidet.
+
+:- pragma no_inline(q/1).
+
+q(X) :- X = a.
+
+:- pred r(int).
+:- mode r(in(any)) is semidet.
+
+:- pragma no_inline(r/1).
+
+r(42).
+
+%---------------------------------------------------------------------------%
+
+:- pred yes(io::di, io::uo) is det.
+
+yes --> io__write_string("yes\n").
+
+:- pred no(io::di, io::uo) is det.
+
+no --> io__write_string("no\n").

-- 
David Overton      Computer Science and Software Engineering
PhD Student        The University of Melbourne   +61 3 8344 9159
Research Fellow    Monash University (Clayton)   +61 3 9905 5779
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list