[m-dev.] [m-users.] Mode selection

Mark Brown mark at mercurylang.org
Wed Oct 22 19:55:59 AEDT 2014


On Tue, Oct 21, 2014 at 2:05 PM, Paul Bone <paul at bone.id.au> wrote:
> On Tue, Oct 21, 2014 at 10:25:17AM +1100, Mark Brown wrote:
>> Moving this to the developers list.
>>
>> On Fri, Oct 17, 2014 at 5:40 PM, Paul Bone <paul at bone.id.au> wrote:
>> > I agree that there should be a full definition for the strict sequential
>> > semantics.  But maybe there should be some "rules" (incomplete definition)
>> > for the normal semantics.
>>
>> We're not in disagreement - I have already given an example of such a rule.
>>
>> > For example it may be useful to specify that:
>> >
>> >     :- pred foo(a, b).
>> >     :- mode foo(in, out) is multi.
>> >     :- mode foo(out, in) is det.
>> >
>> > and
>> >
>> >     foo(bar, baz).
>> >
>> > Results in the second mode (the det mode) being selected.  That is it
>> > probably shouldn't be up to Mercury implementations to choose this obviously
>> > more efficient mode when it can be specified in the language specification.
>> > Or can someone think of a reason why a reasonable implementation might
>> > select the first mode?
>>
>> In the ordering of conjuncts
>>
>>     X = bar, foo(X, Y), Y = baz,
>>
>> the implementation has no choice but to select the first mode. Or are
>> you saying that this ordering shouldn't be allowed?
>
> Neither, I'm saying that in cases like this it will probably be useful for
> the language specification to specify what will happen.  A user will
> reasonably want to know what will happen in this case and they shouldn't
> have to lookup implementation specific behavour.

Okay, I get that. I thought you had a particular rule in mind, but I
couldn't tell what it was from the example.

>
>> What other choices for implied modes should be avoided? E.g., is det
>> always preferred to nondet?
>
> From what I read in the compiler sources (trying to remember back to last
> week) yes, det is preferred.

I know what the compiler implements. The question is, what subset of
this behaviour is guaranteed in the normal (strict commutative)
semantics? This is a question for the developers generally, which is
why I moved the thread to this list. (I recall that rule 3 in the
compiler sources was objected to by developers in the past - i.e., it
ought to be in the strict sequential semantics only - so this question
is not trivial.)

On a related topic, the compiler rejects "indistinguishable" modes,
which is another concept defined in compiler/modecheck_call.m. This
definitely needs to be in the reference manual, but I don't think it
is.

Cheers,
Mark.



More information about the developers mailing list