[m-rev.] for review: fix unused pred warnings for library/store.m

Julien Fischer jfischer at opturion.com
Sun Nov 22 21:46:22 AEDT 2020


On Sat, 21 Nov 2020, Zoltan Somogyi wrote:

> For review by anyone. The diff is with -b.

> Fix unused pred warnings in library/store.m.
> 
> When library/store.m was compiled with LIBARY_INTERMODULE = no,

s/LIBARY/LIBRARY/

> it used to get these warnings:
>
>     store.m:264: Warning: predicate `store_equal'/2 mode 0 is never called.
>     store.m:270: Warning: predicate `store_compare'/3 mode 0 is never called.
> 
> The reason was that
> 
> - the only places that refer to these predicates are the "where equality is"
>   and "where comparison is" clauses of the foreign type definitions
>   for the store/1 type constructor,
> 
> - when the compiler constructs the unify and compare predicates for store/1,
>   it is supposed to make them call store_equal and store_compare respectively,
> 
> - BUT store/1 is listed as a builtin dummy type, along with io.state.
>   They are indeed dummy types in the sense that they don't need any
>   representation, but they are NOT dummy types in the sense that
>   they have one function symbol which is a constant.
> 
> - Nevertheless, because of this, the unify and compare predicates for store/1
>   used to get a clause body that always succeeds, since that is what is
>   appropriate for a type that has one function symbol which is a constant.
> 
> For I/O states, this does not matter, since the in,in mode of the arguments
> of the unify and compare predicates means that any I/O state being compared
> cannot be used either as a di input or as a uo output, so such erroneous
> comparisons would always have been detected, though the error message
> would have been misleading. For stores, any attempts to unify or compare them
> would have silently succeeded. Even though store_equal and store_compare
> were designed to abort the program in such an event, the old, wrong code in
> unify_proc.m meant that they were never called.
> 
> This meant that store_equal and store_compare were never called, but with
> intermodule optimization turned on (the default), the presence of
> opt_exported items such as instances would have suppressed such warnings.

Revise the wording of that paragraph, I don't know what you mean by instances
there.  (The reason the warnings would be suppressed is due to the foreign_type
pragmas being opt_exported.)

> 
> library/io.m:
>     Specify clones of store_equal and store_compare as the type-specific
>     unify and compare predicates for I/O states.
> 
> compiler/unify_proc.m:
>     Now that both builtin dummy type ctors have type-specific unify
>     and compare predicates that always abort, construct their overall
>     unidy and compare predicates from them; do not special case them.

s/unidy/unify/

>
>     Note a potential problem with applying an equality pre-test in
>     user-specified unify and compare predicates that always abort.
>     This includes io.state/0 and store.store/1, but may also include
>     other type constructors.

The compiler could check for (and reject) direct attempts to unify / compare
io.states and stores at compile time.  (That said, programs that attempt to do
that are already pretty contrived ...)

The diff looks fine.

Julien.


More information about the reviews mailing list