[m-dev.] How best to add solver (de)construction preds?

Ralph Becket rafe at cs.mu.OZ.AU
Fri Mar 26 16:26:10 AEDT 2004


A solver type definition of the form

:- solver type t ---> ...
	where constrained is foo(t1 `with_inst` i1, ..., tn `with_inst` iN),
	...

leads to the compiler constructing the following:

:- impure func 'construct foo/N'(t1::in(i1), ..., tn::in(iN)) =
			(t::out(any)) is det.

'construct foo'(X1, ..., XN) = foo(X1, ..., XN).

:- impure pred 'deconstruct foo/N'(t::in, t1::out(i1), ..., tn::out(iN))
			is semidet.

'deconstruct foo'(foo(X1, ..., XN), X1, ..., XN).

The user is required to use these procedures to access the constrained
constructor of the solver type.

Now I need advice as to where and how the compiler should insert these
two procedures.  I tried adding them in make_hlds with suitable changes
to add_item_decl_pass_1 and add_item_clause (for pass 3).  However, this
didn't work for the followng reasons:
- the compiler thinks these are written by the programmer rather than
  the compiler and
- the construction unification isn't an impure function call and
- the deconstruction unification isn't an impure function call and
- the modes in the deconstruction don't work.

So purity checking finds purity errors and mode checking finds mode
errors and the resulting program is rejected by the compiler.

Questions:
(a) Where in the source should the compiler insert these procedures?
(b) How should they be inserted (i.e. what needs to be called to make
this happen)?
(c) Since I also have to insert a pass, after type and mode checking,
but before switch detection, to convert uses of these procedures into 
the underlying (impure) unifications, what would be a good way of
marking these procedures in the HLDS for that pass?

Ta,
-- Ralph
--------------------------------------------------------------------------
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