[mercury-users] tabling

Tyson Dowd trd at cs.mu.OZ.AU
Wed Nov 29 11:40:01 AEDT 2000


On 28-Nov-2000, Dominique de Waleffe <ddw at miscrit.be> wrote:
> Is it not possible to have the tabling code do simple pointer comparisons in
> some cases?
> In the case at hand, the map() argument is something computed at the time
> the service starts and remains constant throughout the run (we are talking
> about weeks...). On the contents of the map, we have several functions/pred
> which compute derived properties, sometimes not immediate and with those
> computations often repeated....

In that case, why not implement a

:- func get_constant_map = map(....)).

function.

If the map is constant, you can implement it using some impure code, and
promise that it is pure.  E.g.


:- pragma c_header_code("
external MR_Word global_map;
").
:- pragma c_code("
MR_Word global_map;
").

:- impure pred set_map(map(...)::in) is det.
:- pragma c_code(set_map(M::in) is det), " global_map = M; ").

:- impure pred get_map(map(...)::out) is det.
:- pragma c_code(set_map(M::in) is det), " M = global_map; ").

:- pred set_map_in_io(map(...)::in, io__state::di, io__state::uo) is det.
set_map_in_io(M::in) -->
	{ impure set_map(M) }.

:- pragma promise_pure(get_map_in_io/3).
:- pred get_map_in_io(map(...)::out, io__state::di, io__state::uo) is det.
set_map_in_io(M::out) -->
	{ impure get_map(M) }.

	% This is not *really* pure -- we should also check to see that
	% we have set the map.
	% If we change set_map to abort if the map is already set, and
	% get_map to abort when the map is uninitialized, then this is
	% really pure.
:- pragma promise_pure(get_constant_map/1).
:- pred get_constant_map(map(...)::out) is det.
get_constant_map(M::out) -->
	{ impure get_map(M) }.


(note that I haven't tested this code, but I'm quietly confident that it
is mostly right).


You can now remove the map argument from the memoized predicate
parameters.  This might solve your immediate problem (but it isn't
necessarily the nicest solution).

> Would it be possible to hint at the compiler that, for a given predicate to
> be memoised, one or several arguments are to be considered as constant?

This would be nice.  I suspect you could do this using an object(T) type
which has object identity (for example, pointer identity is the equality
axiom).  Then it just has to compare the pointer type to be sure it is
the same map.

-- 
       Tyson Dowd           # 
                            #  Surreal humour isn't everyone's cup of fur.
     trd at cs.mu.oz.au        # 
http://www.cs.mu.oz.au/~trd #
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list