[m-dev.] Quick solver types question

David Overton dmo at cs.mu.OZ.AU
Wed Feb 4 19:33:08 AEDT 2004


On Wed, Feb 04, 2004 at 05:07:51PM +1100, Ralph Becket wrote:
> Quick question: you mentioned that the Mercury mode checker will
> automatically insert calls to initilisation predicates for solver types
> when a variable has to be converted from inst free to inst any.  I wrote
> a little program to see what gets generated, but the compiler had a
> whinge:
> 
> :- module foo.
> 
> :- interface.
> 
> :- solver type t ---> a(int).
> 
> :- implementation.
> 
> :- func hmm = (t::out(any)) is det.
> hmm = id(_).
> 
> :- func id(t::in(any)) = (t::out(any)) is det.
> id(X) = X.
> 
> Then...
> $ mmc --make foo
> Making Mercury/int3s/foo.int3
> Making Mercury/cs/foo.c
> foo.m:010: In clause for `hmm = out(any)':
> foo.m:010:   in argument 1 of call to function `foo.id/1':
> foo.m:010:   sorry, implied modes not implemented.
> foo.m:010:   Variable `V_2' has instantiatedness `free',
> foo.m:010:   expected instantiatedness was `any'.
> For more information, try recompiling with `-E'.
> ** Error making `Mercury/cs/foo.c'.
> 
> Looking at modecheck_call.m it seems that
> modecheck_call.modecheck_end_of_call is responsible for actually
> scheduling the goal and is where, I presume, the calls to initialise
> free solver variables should be introduced.  However, that predicate
> ignores the actual insts of the argument variables and just uses the
> insts from the argument modes of the procedure being scheduled.  So it
> doesn't have enough information to insert initialisation calls.
> 
> If code for the introduction of the initialisation calls still needs to
> be written, I take it this is one of the places to do so?
> 
> If you get a chance to give me a pointer on this one I'd be very
> grateful - but I understand completely that you're out of here and have
> a *heap* of stuff to sort out!
> 

The call to the initialisation predicate is added by the code which
handles implied modes.  See predicate modes.handle_implied_mode/8.
This code checks whether the initialisation predicate exists -- in your
example it should be called foo.t_init_any/1 -- and will report a mode
error, like the one give above, if it does not.

You probably want to change this code so that, instead of hard-coding
the predicate name, it gets it from the `:- type ... where init is ...'
declaration instead.

David
-- 
David Overton                  Uni of Melbourne     +61 3 8344 1354
dmo at cs.mu.oz.au                Monash Uni (Clayton) +61 3 9905 9373
http://www.cs.mu.oz.au/~dmo    Mobile Phone         +61 4 0337 4393
--------------------------------------------------------------------------
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