[m-dev.] ground >> dead
Ian MacLarty
maclarty at csse.unimelb.edu.au
Tue Jan 16 11:20:57 AEDT 2007
On Mon, Jan 15, 2007 at 11:27:13PM +1100, Mark Brown wrote:
> On 15-Jan-2007, Julien Fischer <juliensf at csse.unimelb.edu.au> wrote:
> >
> > On Mon, 15 Jan 2007, Mark Brown wrote:
> > > main(!IO) :-
> > > p("foo", X),
> > > write_string(X, !IO),
> > > nl(!IO).
> > >
> > > :- pred p(string::ground >> dead, string::out) is det.
> > >
> > > p(X, X).
> > >
> > >It's hard to see that this mode is useful, however, since it imposes a
> > >restriction on the caller for which there is no corresponding gain (that
> > >I can see).
> >
> > I think that it was an attempt to disallow further forward references to the
> > argument (it makes more sense if you change the argument in your example
> > to a variable).
>
> Yes. If the body of main is changed to
>
> W = "foo",
> p(W, X),
> write_string(X, !IO),
> write_string(W, !IO),
> nl(!IO)
>
> then the following is reported:
>
> t.m:012: In clause for `main(di, uo)':
> t.m:012: in argument 1 of call to predicate `t.p'/2:
> t.m:012: unique-mode error: the called procedure would clobber its argument,
> t.m:012: but variable `W' is still live.
>
> even though
>
> W = "foo",
> V = W,
> p(W, X),
> write_string(X, !IO),
> write_string(V, !IO),
> nl(!IO)
>
> (which is operationally equivalent, but avoids the forward reference) is
> accepted.
>
> > At the very least the compiler should give you a warning with modes like
> > this.
>
> On closer reading of the reference manual, I think it should be an error.
> Dead is defined as "there are no references to the corresponding value", but
> this isn't true for p unless the first argument initially contains the last
> (i.e., unique) reference to the corresponding value.
>
That's what I thought. I asked because one of my fellow Mercury
programmers at MC used this technique to try to stop a parser from being
used after it was closed. Although the code compiled, I said in my
review comments that I didn't think using ground >> dead was such a good
idea for the reasons mentioned above.
Do you think it'd be worth adding a pass to the compiler that gave an
error (or a warning?) if it found any dubious modes?
Ian.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at csse.unimelb.edu.au
Administrative Queries: owner-mercury-developers at csse.unimelb.edu.au
Subscriptions: mercury-developers-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the developers
mailing list