[m-dev.] Re: For review: compiler support for parallel conjunction

Fergus Henderson fjh at cs.mu.oz.au
Wed Oct 22 05:31:56 AEST 1997


Mark Wielaard, you wrote:
> Fergus Henderson <fjh at cs.mu.oz.au> writes:
> 
> >Hmm, what about examples like
> 
> >	:- pred p(out) is det.
> >	p(X) :-
> >		(
> >			X = a,
> >			...
> >			error("blah")
> >		&
> >			X = b,
> >			...
> >		).
> >?
> 
> What is this code supposed to do?
> The code in the first part is erroneous, wouldn't that suggest that the
> predicate p/1 would also be erroneous?

Yes.

(But when we extend things to support semidet parallel conjunctions,
the `...' parts might fail.)

> And since it is erroneous wouldn't it be enough to just execute
> the first part?

It would be enough, yes; but Tom's diff didn't make the compiler do that.

Also doing that optimization would change the operational semantics
in a way that might be undesirable.  In particular, it assumes that
the thread scheduling strategy is allowed to be unfair.
Consider this example:

	:- pred p(out) is det.
	p(X) :-
		(
			X = a,
			...
			q1
		&
			X = b,
			...
			q2
		).

	:- pred q1 is erroneous.
	q1 :- q1.

	:- pred q2 is erroneous.
	q2 :- error("blah").

If you assume a fair thread scheduling policy, then this is guaranteed
to call error("blah").  But with the suggested optimization, it might
loop forever, never calling error/1.

The language should not _prevent_ a fair scheduling policy.
So it can't require that sort of optimization.
Instead, I think it would be better to change the way we
do mode-checking (and the way we define mode-correctness)
to make that sort of thing a mode error.
This could either be just a change in the way we mode check
parallel conjunctions or perhaps a more general change.

> And what if the code in the second 
> part is failure, would you still bother executing anything?

That depends on the semantic model that the user has chosen.
The compiler can only replace determinism `failure' with `fail'
if you specify that the semantics need not be fully strict
(i.e. if you compile with `--no-fully-strict'), because
this optimization might optimize away loops or calls to error/1.
(See the "Semantics" chapter of the Mercury language reference
manual.)

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