[m-rev.] diff: reset contains_trace_goal if necessary

Mark Brown mark at csse.unimelb.edu.au
Fri Nov 10 17:02:23 AEDT 2006


On 10-Nov-2006, Peter Schachte <schachte at csse.unimelb.edu.au> wrote:
> On Fri, Nov 10, 2006 at 12:40:32PM +1100, Mark Brown wrote:
> > First, inline q/1 in p/1, making the implicit promise explicit:
> > 
> > 	p(X) :-
> > 		promise_pure (
> > 			trace ...,
> > 			r(X)
> > 		),
> > 		s(X).
> > 
> > Then remove unnecessary code:
> > 
> > 	p(X) :-
> > 		s(X).
> 
> 
> But this doesn't help the case where you've got:
> 
> 	p(...) :-
> 		trace( ... about to do q ... ),
> 		q(...),
> 		trace( ... finished with q ... ),
> 		trace( ... about to do r ... ),
> 		r(...),
> 		trace( ... finished with r ... ).
> 
> and you need to reorder q and r.  If you consider the trace goals to
> be impure without affecting the purity of p, then you can't reorder q
> and r, and compilation fails.

You could do this with two auxiliary predicates: q_traced and r_traced.
Or if the "trace impurity" doesn't propagate outside of promise_pure scopes,
then you could wrap each part in its own promise.

> If OTOH you consider the trace goals to
> be pure but special in that they can't be optimized away despite being
> det and having no outputs, then the trace goals will happen at the
> wrong times.

Yes, I agree with this.  Simply making the existing ones pure would be a
problem.

> 
> If you instead had
> 
> 	p(...) :-
> 		trace([...],
> 		      ( ... about to do q ... ),
> 		      q(...),
> 		      ( ... finished with q ... )),
> 		trace([...],
> 		      ( ... about to do r ... ),
> 		      r(...),
> 		      ( ... finished with r ... )).
> 
> then the trace goals would be reordered or eliminated with the pure
> goals.

This approach would make it difficult to implement trace goals which, when
enabled, you definitely don't want optimised away.  Trace goals for the G12
propagation engine would fall into this category.  You would need to
contrive some goal that you knew the compiler couldn't remove, such as
putting the trace scope around `impure_true', and then carefully promising
somewhere higher up that the goal is pure.  If you get it wrong, which
would be easy to do, your trace model will be broken.

Cheers,
Mark.

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



More information about the reviews mailing list