[m-dev.] [reuse] fixes of some naughty bugs

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Mar 9 20:25:49 AEDT 2001


On 09-Mar-2001, Nancy Mazur <Nancy.Mazur at cs.kuleuven.ac.be> wrote:
> > This change made me wonder:  how do you handle impure code?  It occurred to
> > me that a foreign predicate could easily store away a term that was passed
> > in, and another foreign pred could return it back to Mercury, creating a
> > perfectly invisible alias.  Such foriegn predicates really should be
> > declared impure and semipure, respectively.  I'm afraid this means that you
> > have to assume that all arguments of every impure or semipure goal are
> > aliased.  You may be able to do a little better than this, but probably not
> > much.
> 
> In order to be able to answer your question, what is exactly 
> meant by a foreign predicate? 

A predicate defined in some other language (e.g. C).

> I thought that impure predicates only occur when somewhere
> down deep one uses some pragma_foreign_code?

Yes, either that or an impure builtin procedure.

By a "builtin" procedure I mean one for which the compiler generates inline
code automatically, without any explicit definition of that procedure in the
standard library source code.  Currently there aren't any impure builtins, but
that is likely to change; e.g. the impure procedures used by the MLDS back-end
for tabling, which are currently implemented using `pragma c_code'/`pragma
foreign_code', really ought to be implemented as builtins, since that
would result in much better code generation for the native-code back-end
(--target asm), and probably for the other non-C back-ends too.

In the HLDS a call to a builtin procedure is marked with the `builtin_state'
field of the call being `inline_builtin'.

> But if this is the case, as all pragma_foreign_code is always
> assumed impure,

That's not the case currently (at least on the main branch).
Currently pragma_foreign_code is assumed pure.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list