[m-rev.] for review: more standardization of interface files

Julien Fischer juliensf at cs.mu.OZ.AU
Wed May 25 02:05:44 AEST 2005


On Tue, 24 May 2005, Zoltan Somogyi wrote:

> For review by Julien.
>
> Zoltan.
>
> compiler/modules.m:
> 	Change the way we filter out redundant flips between interface and
> 	implementation section markers in interface files. When I added a new
> 	implementation section to hlds_pred.m, I noticed that the .int3 file
> 	had changed unnecessarily (even before I added the new clause_rep
> 	type). This was because the compiler added a new :- implementation
> 	and :- interface pair into it. This change filters out flips not just
> 	in triples of :- implementation/:- interface/:- implementation,
> 	but also doubles. For modules such as hlds_pred.m, it now puts all
> 	types in the .int3 in the same interface section, instead of several
> 	separate interface sections. This allows more kinds of changes to the
> 	source to have no effect on the .int3 file.
>
> 	Convert the original semidet predicate into a det bool function,
> 	to force us to consider all kinds of items. As a result, make a
> 	few more kinds of items reorderable and chunkable, to allow better
> 	standardization of interface files.
>
...

> Index: compiler/modules.m
> ===================================================================
> RCS file: /home/mercury/mercury1/repository/mercury/compiler/modules.m,v
> retrieving revision 1.332
> diff -u -b -r1.332 modules.m
> --- compiler/modules.m	23 May 2005 03:15:38 -0000	1.332
> +++ compiler/modules.m	24 May 2005 06:52:58 -0000
> @@ -7440,12 +7440,12 @@
>  :- pred order_items(item_list::in, item_list::out) is det.
>
>  order_items(Items0, Items) :-
> -    do_order_items(Items0, Items1),
> +    filter_unnecessary_flips(Items0, other, Items1),
> +    do_order_items(Items1, Items2),
>          % Delete any redundant :- interface and :- implementation markers
>          % at the end, to make Items as insensitive as we can to the number
>          % of interface sections in the source file. If some of the
>          % implementation sections are not empty, we won't be fully successful.
> -    filter_unnecessary_flips(Items1, Items2),
>      list__reverse(Items2, RevItems2),
>      list__takewhile(interface_or_import_marker, RevItems2, _, RevItems),
>      list__reverse(RevItems, Items).
> @@ -7455,26 +7455,40 @@
>  interface_or_import_marker(module_defn(_, interface) - _).
>  interface_or_import_marker(module_defn(_, implementation) - _).
>
> -:- pred filter_unnecessary_flips(item_list::in, item_list::out) is det.
> -
> -filter_unnecessary_flips([], []).
> -filter_unnecessary_flips([Item], [Item]).
> -filter_unnecessary_flips([Item1, Item2], [Item1, Item2]).
> -filter_unnecessary_flips([Item1, Item2, Item3 | Items0], Items) :-
> +:- type cur_pos
> +    --->    in_interface
> +    ;       in_implementation
> +    ;       other.
> +
I assume 'other' is for the case where the compiler appends new items
on to the item list without specifying whether they are in the interface
or implementation; in any case a brief comment about why 'other' is
necessary would be helpful here.

> +:- pred filter_unnecessary_flips(item_list::in, cur_pos::in, item_list::out)
> +    is det.
> +
> +filter_unnecessary_flips([], _, []).
> +filter_unnecessary_flips([Item], _, [Item]).
> +filter_unnecessary_flips([Item1, Item2 | Items0], CurPos, Items) :-
>      (
> -        Item1 = module_defn(_, interface) - _,
> -        Item2 = module_defn(_, implementation) - _,
> -        Item3 = module_defn(_, interface) - _
> +        CurPos = in_interface,
> +        Item1 = module_defn(_, implementation) - _,
> +        Item2 = module_defn(_, interface) - _
>      ->
> -        filter_unnecessary_flips([Item3 | Items0], Items)
> +        filter_unnecessary_flips(Items0, CurPos, Items)
>      ;
> -        Item1 = module_defn(_, implementation) - _,
> -        Item2 = module_defn(_, interface) - _,
> -        Item3 = module_defn(_, implementation) - _
> +        CurPos = in_implementation,
> +        Item1 = module_defn(_, interface) - _,
> +        Item2 = module_defn(_, implementation) - _
>      ->
> -        filter_unnecessary_flips([Item3 | Items0], Items)
> +        filter_unnecessary_flips(Items0, CurPos, Items)
> +    ;
> +        ( Item1 = module_defn(_, implementation) - _ ->
> +            NextPos = in_implementation
> +        ; Item1 = module_defn(_, interface) - _ ->
> +            NextPos = in_interface
> +        ; chunkable_item_and_context(Item1) = yes ->
> +            NextPos = CurPos
>      ;
> -        filter_unnecessary_flips([Item2, Item3 | Items0], ItemsTail),
> +            NextPos = other
> +        ),
> +        filter_unnecessary_flips([Item2 | Items0], NextPos, ItemsTail),
>          Items = [Item1 | ItemsTail]
>      ).
>
...


> @@ -7516,65 +7530,169 @@
>  import_or_use(module_defn(_, import(_)) - _).
>  import_or_use(module_defn(_, use(_)) - _).
>
> -    % The kinds of items for which reorderable succeeds can be arbitrarily
> +:- pred is_reorderable(item_and_context::in) is semidet.
> +
> +is_reorderable(ItemAndContext) :-
> +    reorderable_item_and_context(ItemAndContext) = yes.
> +
> +:- func reorderable_item_and_context(item_and_context) = bool.
> +
> +reorderable_item_and_context(Item - _Context) =
> +    reorderable_item(Item).
> +
> +    % The kinds of items for which reorderable_item succeeds can be arbitrarily
>      % reordered with respect to each other and with respect to other chunkable
>      % items in all kinds of interface files (.int, .int2, .int3, and .int0).
>      % This predicate is not relevant to .opt and .trans_opt files, since those
>      % are generated from the HLDS, not from item_lists.
>      %
s/reorderable_item succeeds/reorderable_item returns 'yes'/ in the above
comment.

> -:- pred reorderable(item_and_context::in) is semidet.
> +:- func reorderable_item(item) = bool.
> +
> +reorderable_item(module_defn(_, ModuleDefn)) = Reorderable :-
> +    ( ModuleDefn = import(_), Reorderable = yes
> +    ; ModuleDefn = abstract_imported, Reorderable = no
> +    ; ModuleDefn = end_module(_), Reorderable = no
> +    ; ModuleDefn = export(_), Reorderable = yes
> +    ; ModuleDefn = external(_, _), Reorderable = yes
> +    ; ModuleDefn = implementation, Reorderable = no
> +    ; ModuleDefn = imported(_), Reorderable = no
> +    ; ModuleDefn = include_module(_), Reorderable = no
> +    ; ModuleDefn = interface, Reorderable = no
> +    ; ModuleDefn = module(_), Reorderable = no
> +    ; ModuleDefn = opt_imported, Reorderable = no
> +    ; ModuleDefn = private_interface, Reorderable = no
> +    ; ModuleDefn = transitively_imported, Reorderable = no
> +    ; ModuleDefn = use(_), Reorderable = yes
> +    ; ModuleDefn = used(_), Reorderable = no
> +    ; ModuleDefn = version_numbers(_, _), Reorderable = no
> +    ).
> +reorderable_item(pragma(Pragma)) = Reorderable :-
> +    ( Pragma = aditi(_, _), Reorderable = no
> +    ; Pragma = aditi_index(_, _, _), Reorderable = no
> +    ; Pragma = aditi_memo(_, _), Reorderable = no
> +    ; Pragma = aditi_no_memo(_, _), Reorderable = no
> +    ; Pragma = base_relation(_, _), Reorderable = no
> +    ; Pragma = check_termination(_, _), Reorderable = yes
> +    ; Pragma = context(_, _), Reorderable = no
> +    ; Pragma = does_not_terminate(_, _), Reorderable = yes
> +    ; Pragma = exceptions(_, _, _, _, _), Reorderable = no
> +    ; Pragma = export(_, _, _, _), Reorderable = yes
> +    ; Pragma = fact_table(_, _, _), Reorderable = no
> +    ; Pragma = foreign_code(_, _), Reorderable = no
> +    ; Pragma = foreign_decl(_, _, _), Reorderable = no
> +    ; Pragma = foreign_import_module(_, _), Reorderable = no
> +    ; Pragma = foreign_proc(_, _, _, _, _, _), Reorderable = no
> +    ; Pragma = import(_, _, _, _, _), Reorderable = no
> +    ; Pragma = inline(_, _), Reorderable = yes
> +    ; Pragma = mode_check_clauses(_, _), Reorderable = yes
> +    ; Pragma = naive(_, _), Reorderable = no
> +    ; Pragma = no_inline(_, _), Reorderable = yes
> +    ; Pragma = obsolete(_, _), Reorderable = yes
> +    ; Pragma = owner(_, _, _), Reorderable = no
> +    ; Pragma = promise_pure(_, _), Reorderable = yes
> +    ; Pragma = promise_semipure(_, _), Reorderable = yes
> +    ; Pragma = psn(_, _), Reorderable = no
> +    ; Pragma = reserve_tag(_, _), Reorderable = yes
> +    ; Pragma = source_file(_), Reorderable = no
> +    ; Pragma = supp_magic(_, _), Reorderable = no
> +    ; Pragma = tabled(_, _, _, _, _), Reorderable = yes
> +    ; Pragma = terminates(_, _), Reorderable = yes
> +    ; Pragma = termination2_info(_, _, _, _, _, _, _), Reorderable = no
> +    ; Pragma = termination_info(_, _, _, _, _), Reorderable = yes
> +    ; Pragma = type_spec(_, _, _, _, _, _, _, _), Reorderable = yes
> +    ; Pragma = unused_args(_, _, _, _, _), Reorderable = yes
> +    ).
> +reorderable_item(type_defn(_, _, _, _, _)) = yes.
> +reorderable_item(inst_defn(_, _, _, _, _)) = yes.
> +reorderable_item(mode_defn(_, _, _, _, _)) = yes.
> +reorderable_item(promise(_, _, _, _)) = yes.
> +reorderable_item(typeclass(_, _, _, _, _, _)) = yes.
> +reorderable_item(instance(_, _, _, _, _, _)) = yes.
> +reorderable_item(clause(_, _, _, _, _)) = no.
> +reorderable_item(nothing(_)) = no.
> +reorderable_item(pred_or_func(_, _, _, _, _, _, _, _, _, _, _, _)) = no.
> +reorderable_item(pred_or_func_mode(_, _, _, _, _, _, _)) = no.
> +
It would be better if this function called unexpected/2 for those
items that should not occur in interface files.  (These items should have
been filtered out when the list of interface items was constructed.)
Pragmas that are allowed in interfaces are listed in the definition of
pragma_allowed_in_interface/2.  The same should probably happen for
module definitions that are used internally by the compiler.

That looks good otherwise.

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