[mercury-users] Possible state var / uniqueness bug Re: Request for comments on this code

Julien Fischer juliensf at csse.unimelb.edu.au
Mon Jul 10 19:06:38 AEST 2006


On Mon, 10 Jul 2006, Peter Moulder wrote:

> On Mon, Jul 10, 2006 at 04:18:59PM +1000, Julien Fischer wrote:
> >
> > On Mon, 10 Jul 2006, Peter Moulder wrote:
> >
> > > Is this a compiler bug?  Or how should tst2.m be written such that it
> > > uses state-variable syntax for its io vars, and has an I/O call as the
> > > condition of an if-then-else?
> >
> > It's a compiler bug - you aren't supposed be allowed to do I/O in the
> > condition of an if-then-else.
>
> I don't see this restriction mentioned in (mercury_ref)Goals, or any of
> the subsections of (mercury_ref)Unique modes.  I suggest that these are
> the obvious places to look for a person wondering "is this valid Mercury
> code".
>
> Furthermore, it isn't clear to me why it should be forbidden (except
> perhaps for stylistic reasons, at least if an alternative like `&&'
> existed).  The compiler knows that the condition can't fail, so I
> believe it's just a case of `CONDGOAL && THENGOAL', i.e. declaratively
> equivalent to `CONDGOAL, THENGOAL'.

The compiler _will_ know that the condition cannot fail ... but not
until after determinism analysis.  Most of mode checking occurs before
that.  Simplifying ( A -> B ; C) into (A, B) if A cannot fail doesn't
occur until later.  As far as most of the frontend of the compiler is
concerned if-then-elses have the semantics listed in the section 2.9
of the reference manual, i.e. ( A, B ; not(A), C).

> Btw, I haven't tested this code in current 0.13 betas; from memory,
> Julien mentioned in a June 23 post to this list that these versions
> include a fix for a mode analysis bug.

That fix was for a bug with state variable expansion**.  The bug caused
a mode error to be reported but it wasn't a mode analysis bug as such.

** The problem was that expanding state variables was incorrect with
respect to nested closures where one closure referred to the current
state of a state variable in the enclosing scope.

Julien.

--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at csse.unimelb.edu.au
administrative address: owner-mercury-users at csse.unimelb.edu.au
unsubscribe: Address: mercury-users-request at csse.unimelb.edu.au Message: unsubscribe
subscribe:   Address: mercury-users-request at csse.unimelb.edu.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list