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

Mark Brown mark at csse.unimelb.edu.au
Fri Nov 10 12:40:32 AEDT 2006


On 10-Nov-2006, Ian MacLarty <maclarty at csse.unimelb.edu.au> wrote:
> On Thu, Nov 09, 2006 at 05:22:15PM +1100, Ian MacLarty wrote:
> > On Thu, Nov 09, 2006 at 04:34:16PM +1100, Mark Brown wrote:
> > > For example, the goal
> > > 
> > > 	( Cond ->
> > > 		trace ...
> > > 	;
> > > 		trace ...
> > > 	)
> > > 
> > > should not be replaced with "true" unless both trace goals are compiled
> > > away.
> > > 
> > > In effect, trace goals introduce a kind of impurity which is eliminated
> > > by promise_pure (as with other kinds of impurity), but which is also
> > > implicitly eliminated at the boundary of each clause.  I believe this
> > > was Zoltan's intent.
> > > 
> > 
> > That sounds reasonable to me.
> > 
> 
> Actually no it doesn't.  Trace goals are completely outside of the
> declarative semantics of the program, so they have no effect on purity 
> whatsoever.

There's nothing else to stop trace goals from always being optimised away.

> 
> I think the current behaviour is fine, except for the issue Pete raised.

The behaviour I mentioned is intended to address this issue.  Here's what I
mean:

On 08-Nov-2006, Peter Ross <pro at missioncriticalit.com> wrote:
> Imagine we have a program.
>
> p(X) :-
>  q(X),
>  s(X).
>
> q(X) :-
>  trace(..),
>  r(X).
>
> Now imagine the compiler determines q(X) and r(X) don't actually need
> to be called.
> The behaviour of the program with respect to the trace goals will
> depend on whether or not inlining is done before or after unnecessary
> code removal.

First, inline q/1 in p/1, making the implicit promise explicit:

	p(X) :-
		promise_pure (
			trace ...,
			r(X)
		),
		s(X).

(This isn't exactly right, since the promise is only meant to eliminate
the "impurity" of the trace goal.  But we have no other syntax so this will
have to suffice.)

Then remove unnecessary code:

	p(X) :-
		s(X).

which is the same result you would get if removing unnecessary code was
done first.

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