[m-rev.] for review: constant mutables

Julien Fischer juliensf at cs.mu.OZ.AU
Wed Apr 26 17:49:40 AEST 2006


On Wed, 26 Apr 2006, Zoltan Somogyi wrote:

> Support constant "mutables". Though this sounds like a contradiction in terms,
> they can be useful, because in some cases they are the best alternative.
>
> - For some types, e.g. arrays, there is no way to write manifest constants.
>
> - For some other types, one can write manifest constants, but the compiler
>   may be too slow in compiling clauses containing them if the constant is
>   very large (even after my recent improvements).
>
> - Using a tabled zero-arity function incurs overhead on every access to check
>   whether the result was recorded previously or not. This is a bad idea e.g.
>   in the inner loop of a scanner (which may want to use an array for the
>   representation of the DFA).
>
> compiler/prog_item.m:
> 	Add a new attribute to say whether the mutable is constant or not.
>
> compiler/prog_io.m:
> 	Recognize the "constant" mutable attribute.
>
> compiler/prog_mutable.m:
> 	Provide predicates to construct the signatures of the get and set
> 	predicates of constant mutables. Rename some existing predicates
> 	to better reflect their purpose.
>
> compiler/make_hlds_passes.m:
> compiler/modules.m:
> 	Modify the code for creating mutables' get, set and init predicates
> 	to do the right thing for constant mutables.
>
> doc/reference_manual.texi:
> 	Document the new attribute.
>
> tests/hard_coded/pure_mutable.{m,exp}:
> 	Test the new attribute.

You need to update the NEWS file as well.

...

> Index: compiler/prog_mutable.m
> ===================================================================
> RCS file: /home/mercury/mercury1/repository/mercury/compiler/prog_mutable.m,v
> retrieving revision 1.9
> diff -u -b -r1.9 prog_mutable.m
> --- compiler/prog_mutable.m	29 Mar 2006 08:07:18 -0000	1.9
> +++ compiler/prog_mutable.m	26 Apr 2006 05:08:56 -0000
> @@ -24,35 +24,48 @@
>
> -    % predicate.
> +    % Create a predmode declaration for a get predicate using the I/O state.
> +    % (This is created only if the `pure' mutable attribute is given.)
>      %

Although it's not really part of your change: there is no `pure' attribute,
that should be `attach_to_io_state' (and below as well).

> -:- func init_pred_decl(module_name, string) = item.
> +:- func io_get_pred_decl(module_name, string, mer_type, mer_inst) = item.
> +
> +    % Create a predmode declaration for a set predicate using the I/O state.
> +    % (This is created only if the `pure' mutable attribute is given.)
> +    %
> +:- func io_set_pred_decl(module_name, string, mer_type, mer_inst) = item.
> +

...

> @@ -138,6 +173,9 @@
>
>  mutable_set_pred_sym_name(ModuleName, Name) =
>      qualified(ModuleName, "set_" ++ Name).
> +
> +mutable_secret_set_pred_sym_name(ModuleName, Name) =
> +    qualified(ModuleName, "secret_initialization_only_set_" ++ Name).

A minor point: there doesn't seem to be anything stop me creating my own
predicate with that name.  It's probably worth putting an XXX comment about
that somewhere.

...

> ===================================================================
> RCS file: /home/mercury/mercury1/repository/mercury/doc/reference_manual.texi,v
> retrieving revision 1.350
> diff -u -b -r1.350 reference_manual.texi
> --- doc/reference_manual.texi	11 Apr 2006 01:05:15 -0000	1.350
> +++ doc/reference_manual.texi	26 Apr 2006 05:34:13 -0000
> @@ -4777,6 +4777,12 @@
>  :- pred set_varname(vartype::in(varinst),  io::di, io::uo) is det.
>  @end example
>
> + at item @samp{constant}
> +This attribute causes the compiler to construct
> +only a @samp{get} access predicate, but not a @samp{set} access predicate.
> +Since @samp{varname} will always have the initial value given to it,
> +the @samp{get} access predicate is pure.
> +
>  @end table

I think this should be more explicit about the fact that the `constant'
and `attach_to_io_state' attributes are not compatible with each other.
I think it's also worth stating what the signature for this get predicate is.

Julien.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list