[m-dev.] Term representation and `any' insts - HAL

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Mar 23 19:38:34 AEDT 1999


On 23-Mar-1999, Warwick Harvey <wharvey at cs.monash.edu.au> wrote:
> Fergus wrote:
> > The presumption was that cases like this would be handled in the same
> > way that Prolog handles them, by using a level of indirection,
> > and thus passing a pointer in rather than passing a value in and a value out.
> > 
> > Is there any particular reason why you don't want to use that technique?

> ... we're using a Parma binding scheme ...

Ah, yes, I remember now.

I did warn you that getting the Mercury compiler to handle a Parma
binding scheme would be difficult...

> We'd like to avoid the level of indirection if we know something is ground 
> (so you only pay when you need it).  In particular, we (originally) wanted 
> to be able to pass a (now) ground data structure to a Mercury library 
> predicate, and have it work.  This seems perhaps a little less useful now, 
> since we're going to want to add new modes to many of the (Mercury) library 
> predicates, which means we may end up building our own library anyway...  
> But I digress.
> 
> Anyway, we're using a Parma binding scheme, which means any references to a 
> variable embedded in some data structure are updated when the variable is 
> bound.  We could do this for "standalone" copies of the variable too, except 
> that we don't really want to add to the Parma chain every time Mercury 
> copies the variable.  So we only add it when constructing new terms, etc.  
> The "standalone" copies are (currently) intended to be handled properly by 
> their modes: if the compiler thinks it's `any', it gets extra checks; if the 
> compiler thinks it's bound, it skips the checks.  Then if we just make sure 
> the variable is dereferenced and possibly updated any time there's a 
> transition from `any' to `bound', it should all work.  :-)

Could you elaborate?

Do you mean that every time you bind a variable, you also
check any other "standalone" variables in the current
procedure to see if they alias the variable you're binding,
so that you can bind them too?

If so, what about "standalone" variables in your callers?
Wouldnt't this mean that every time you bind a variable,
you need to search up the call stack, checking for
other variables that might alias it, and binding them too?

> > I don't see how your proposed technique could work, in general,
> > since there might be other copies of the `any' inst around.
> > 
> > Consider the following code:
> > 
> > 	:- pred p(herbrand, io__state, io__state).
> > 	:- mode p(in(any), di, uo) is cc_multi.
> > 	p(X) -->
> > 		{ id(X, Y, Z) },
> > 		{ bind(Y) },
> > 		dump(Z).
> > 
> > 	:- pred id(T, T, T).
> > 	:- mode id(in(any), out(any), out(any)).
> > 	id(X, X, X).
> > 
> > 	:- pred bind(herbrand).
> > 	:- mode bind(any -> ground).
> > 
> > 	:- pred dump(herbrand, io__state, io__state).
> > 	:- mode dump(any -> any, di, uo) is cc_multi.
> > 
> > With your scheme, how would the call to bind(Y) bind the value of the
> > aliased variable Z, as is needed for the subsequent call to dump(Z)?
> 
> Since `dump/3' takes something of inst `any', it is obliged to dereference 
> it somehow (probably by checking that it is in a suitable state) before 
> printing it.

Sure.  But how does Z get bound in the first place?

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