[mercury-users] Disable or warn for implicit modes?

Julien Fischer juliensf at csse.unimelb.edu.au
Fri Feb 24 04:59:22 AEDT 2012


Hi,

On Tue, 14 Feb 2012, Jeff Thompson wrote:

> Hello.  Sometimes the compiler will create an implicit mode which is
> not declared.  For example, if the predicate  argument only has an
> "out" mode but is called with "in", it will call the predicate with a
> temporary "out" argument and check for equality on return.

Yes, this is what is referred to as an implied mode.  Note that the
compiler will only do this in the absence of a mode that exactly matches
the mode required by the call to the predicate.

> But if this is done when there are different clauses for different
> modes, it can cause unexpected behavior.

You mean, it may select the mode that you don't expect?  The easiest way
to avoid this is to provide explicit mode declarations that exactly
match the modes of any calls to the predicate in question.

If you don't do this then the choice of mode is still predicatable,
after all the algorithm used by the mode checker has to eventually
settle on a single mode.  Briefly, the algorithm used by the compiler
is as follows:

Given a candidate set of modes:

(1) remove modes that are strictly less informative or strictly less
instanstiated from the set of candidate modes; if we're left with one
mode then we're done otherwise ...

(2) prioritize the reamining modes by their determinism;
the priority is determined by the position of the determinims in
the determinism lattice -- see section 6.1 ``Determinism categories''
of the reference manual.  If we are left with one mode with the highest
priority then we're done, otherwise ...

(3) If step 2 still doesn't yield a single mode, then the first
mode that occurs in declaration order is the one selected.

> Is there a compiler switch to disable or warn if implicitly calling a 
> predicate with an undeclared mode?

No.

Julien.
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the users mailing list