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

Nancy Mazur Nancy.Mazur at cs.kuleuven.ac.be
Fri Mar 9 22:00:01 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.  

Even then, isn't that translated in terms of the hlds_goal: 
pragma_foreign_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'.

You mean like an ordinary call? But than with that extra annotation? 
Hmmm... 

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

No, not within my analysis: they are implicitly assumed as dangerous 
code, and treated as `can potentially do anything'-code. 

Nancy

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