[m-rev.] for review: [CTGC] user annotated sharing

Julien Fischer juliensf at cs.mu.OZ.AU
Wed Jun 28 17:43:13 AEST 2006


On Tue, 27 Jun 2006, Nancy Mazur wrote:

> Estimated hours taken: 30
> Branches: main
>
> Add the possibility of annotating foreign code with sharing information.
> The sharing information is part of the foreign_proc pragma's, and must be

s/pragma's/pragmas/

> of the following format:
> 	no_sharing 		% meaning that the procedure does not
> 				% create any sharing.
> 	unknown_sharing		% meaning that the procedure creates any
> 				% possible sharing;
> 	sharing(MaybeTypeInformation, SharingList)
> 				% meaning that the procedure creates at most
> 				% the listed sharing.
> where
> MaybeTypes =
> 	yes(Types)
> 	no
> where Types corresponds to the type-signature of the foreign proc (i.e. they
> must be unifiable).

It isn't clear to me how this is supposed to work (but see comments about
reference manual below.)

> The types are only needed when the typeselectors used in
> specifying the sharing make use of type variables.
>
> and
>
> SharingList = list of SharingPair
>
> and
>
> SharingPair = cel(Var1, Typeselectors1) - cel(Var2, Typeselectors2)
>
> where
> 	Var1, Var2 correspond to head variables from the foreign proc;
> 	Typeselectors1, Typeselectors2 correspond to a list of typeselectors,
> 	i.e., a list of types possibly in terms of the types given in
> 	MaybeTypes.
>
> Example:
>
> :- pred array.init_2(int::in, T::in, array(T)::array_uo) is det.
>
> :- pragma foreign_proc("C",
>     array.init_2(Size::in, Item::in, Array::array_uo),
>     [will_not_call_mercury, promise_pure, thread_safe, will_not_modify_trail,
>     sharing(yes(int, T, array(T)), [cel(Item,[]) - cel(Array,[T])])],
> "
>     ML_alloc_marray(Array, Size + 1, MR_PROC_LABEL);
>     ML_init_marray(Array, Size, Item);
> ").
>
> The meaning: a call init_2(Size, Item, Array) may create sharing between
> Item, and any terms of Array with the type T (i.e. the elements of the
> array).
>
> compiler/add_pragma.m:
> compiler/prog_ctgc.m:
> compiler/prog_io_pragma.m:
> 	Parsing/Renaming routines for the user annotated sharing.
>
> compiler/ctgc.util.m:
> 	BUGFIX. The definition of "get_type_substitution" was actually doing
> 	the wrong thing, as it was creating a substitution with which to
> 	rename two type-lists "away" from each other... while the analysis
> 	needs the substitution resulting from unifying the type-lists.
>
> compiler/module_qual.m:
> 	Module qualify the types that are part of the sharing declaration.
>
> compiler/prog_data.m:
> 	Types for recording user annotated sharing.
> 	Change the definition of the public representation for
> 	structure sharing.
>
> compiler/structure_reuse.direct.detect_garbage.m:
> compiler/structure_reuse.indirect.m:
> compiler/structure_sharing.analysis.m:
> compiler/structure_sharing.domain.m:
> 	Use foreign_proc sharing information when computing the overall
> 	sharing.

The new foreign_proc attributes need to be documented in the reference
manual - for the time being the documentation should be commented out
but it should still be added now.

Also, you will (most probably) need to update the predicate replace_in_item/9
in compiler/equiv_type.m, so that equivalence types in the sharing information
are expanded, i.e. that predicate needs to be modified to handle
foreign_procs.  I guess the smart recompilation system may also need to be
changed for this - have a look at the type item_type in
compiler/recompilation.m.

...

> Index: compiler/prog_data.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/compiler/prog_data.m,v
> retrieving revision 1.167
> diff -u -d -r1.167 prog_data.m
> --- compiler/prog_data.m	15 Jun 2006 19:37:08 -0000	1.167
> +++ compiler/prog_data.m	27 Jun 2006 08:28:56 -0000
> @@ -328,9 +328,9 @@
>      % This is the public representation of the type "sharing_as".
>      %
>  :- type structure_sharing_domain
> -    --->    bottom
> -    ;       real(structure_sharing)
> -    ;       top(list(top_feedback)).
> +    --->    structure_sharing_bottom
> +    ;       structure_sharing_real(structure_sharing)
> +    ;       structure_sharing_top(list(top_feedback)).
>
>      % Public representation of structure sharing.
>      %
> @@ -364,6 +364,25 @@
>      --->    termsel(cons_id, int)       % term selector
>      ;       typesel(mer_type).          % type selector
>
> +    % Type to represent the sharing information that is manually added
> +    % to procedures writtin in foreign code.

s/writtin/written/

(although "implemented as foreign_procs." would be be better.)

> +    %
> +:- type user_annotated_sharing
> +    --->    no_user_annotated_sharing
> +    ;       user_sharing(
> +                sharing     ::  structure_sharing_domain,
> +                maybe_types ::  maybe(user_sharing_type_information)
> +            ).
> +
> +    % The user may have declared the sharing in terms of type variables. In
> +    % that case, we record the types, and the type variable set.
> +    %
> +:- type user_sharing_type_information
> +    --->    user_type_info(
> +                types       ::  list(mer_type),
> +                typevarset  ::  tvarset
> +            ).

...

> Index: compiler/structure_sharing.domain.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/compiler/structure_sharing.domain.m,v
> retrieving revision 1.10
> diff -u -d -r1.10 structure_sharing.domain.m
> --- compiler/structure_sharing.domain.m	5 Jun 2006 05:23:27 -0000	1.10
> +++ compiler/structure_sharing.domain.m	27 Jun 2006 08:29:03 -0000
> @@ -149,10 +149,13 @@
>  :- func add_unify_sharing(module_info, proc_info, unification, hlds_goal_info,
>      sharing_as) = sharing_as.
>
> -    % XXX Not yet implemented.
> -% :- func add_foreign_code_sharing(module_info, pred_proc_id, goal_info
> -    % pragma_foreign_proc_attributes, list(foreign_arg),
> -    % sharing_as) = sharing_as.
> +    % Add the sharing created by a call to some foreign code. This
> +    % sharing corresponds to the sharing information with which the
> +    % foreign code was manually annotated, or can be predicted to
> +    % "bottom", and in the worst case to "top".
> +    %
> +:- func add_foreign_code_sharing(module_info, proc_info, pred_proc_id,
> +    pragma_foreign_proc_attributes, prog_context, sharing_as) = sharing_as.

That function would be more accurately named add_foreign_proc_sharing.

...

> +:- pred sharing_as_from_user_annotated_sharing(
> +    pragma_foreign_proc_attributes::in, sharing_as::out) is semidet.
> +
> +sharing_as_from_user_annotated_sharing(Attributes, UserSharingAs) :-
> +    UserSharing = user_annotated_sharing(Attributes),
> +    UserSharing = user_sharing(SharingDomain, _MaybeTypes),
> +    % Accept only the value "bottom" and "real" for the structure sharing.
> +    % If the user has annotated the sharing with unknown sharing, we might
> +    % try to predict bottom anyway.
> +    some [!SharingAs] (
> +        (
> +            SharingDomain = structure_sharing_bottom,
> +            !:SharingAs = sharing_as_bottom
> +        ;
> +            SharingDomain = structure_sharing_real(_SharingPairs),
> +            !:SharingAs = from_structure_sharing_domain(SharingDomain)
> +
> +            % XXX
> +            % I have the feeling that renaming should not be needed at this
> +            % place anymore, assuming that every foreign_proc call is

That sentence is incomplete.

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