Files
mercury/tests/valid/use_import_only_for_instance.m
Zoltan Somogyi ec20b1ed0a Make sparse_bitset.m operate on uints.
NEWS:
    Mention all the user-visible changes below.

library/enum.m:
    Add the typeclass uenum, which is a version of the existing enum typeclass
    that maps items to uints, not ints. It also uses a semidet predicate,
    not a semidet function, to get back to the item from the uint.

library/sparse_bitset.m:
library/fat_sparse_bitset.m:
    Make these modules operate on uints, which means requiring the items
    in the sets to be instances of uenum, not enum.

    If a few places, improve loops by doing previously-repeated conversions
    of [u]ints into <offset, bit-to-set> pairs just once.

library/counter.m:
    Define ucounters, which allocate uints. Improve documentation.

library/digraph.m:
    Change digraph_keys from ints to uints, since we put them into
    sparse_bitsets.

library/int.m:
    Make int an instance of the uenum typeclass. This can help users
    who currently put ints into sparse_bitsets.

library/pprint.m:
    Prettyprint sparse_bitsets as lists of uints.

library/term.m:
    Make vars instances of uenum as well as enum.

library/uint.m:
    Make uint an instance of the uenum typeclass.

    Add the ubits_per_uint function, which allows some casts to be avoided.

compiler/make.deps_set.m:
    Change the indexes we put into sparse_bitsets from ints to uints.

compiler/make.make_info.m:
    Change the source of those indexes from ints to uints.

compiler/make.top_level.m:
compiler/make.util.m:
    Conform to the changes above.

compiler/pre_quantification.m:
    Change zones from ints to uints, since we put them into sparse_bitsets.

tests/hard_coded/int_uenum.{m,exp}:
tests/hard_coded/Mmakefile:
    Enable the new test case.

tests/valid/use_import_only_for_instance.m:
    Update this extract from library/digraph.m the same way as
    library/digraph.m itself.
2022-12-05 09:45:11 +11:00

61 lines
2.0 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et
%---------------------------------------------------------------------------%
%
% The bug that this test case tests for is that the compiler reports
% the import of the "int" module below as unused, even though without it,
% it generates an error saying
%
% In clause for predicate `build_zones_to_dup_vars'/4:
% unsatisfiable typeclass constraints: `enum.enum(int)', `enum.enum(int)'.
%
% This constraint is imposed by the use of sparse_bitset(int).
%
% NOTE The above was written when sparse_bitset.m required the elements to be
% instances of the enum typeclass, not the uenum typeclass, and pvars and
% zones were defined below to be equivalent to ints, not uints.
:- module use_import_only_for_instance.
:- interface.
:- import_module list.
:- import_module map.
:- import_module sparse_bitset.
:- type pvar == uint.
:- type zone == uint.
:- type vars_to_zones == map(pvar, sparse_bitset(zone)).
:- type zones_to_dup_vars == map(zone, list(pvar)).
:- pred build_zones_to_dup_vars(pvar::in, sparse_bitset(zone)::in,
zones_to_dup_vars::in, zones_to_dup_vars::out) is det.
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
:- implementation.
:- import_module uint.
build_zones_to_dup_vars(Var, Zones, !ZonesToDupVars) :-
ZoneList = sparse_bitset.to_sorted_list(Zones),
( if
ZoneList = [FirstZone, _SecondZone | _],
FirstZone \= 0u
then
list.foldl(add_var_to_zone(Var), ZoneList, !ZonesToDupVars)
else
true
).
:- pred add_var_to_zone(pvar::in, zone::in,
zones_to_dup_vars::in, zones_to_dup_vars::out) is det.
add_var_to_zone(Var, Zone, !ZonesToDupVars) :-
( if map.search(!.ZonesToDupVars, Zone, DupVars0) then
DupVars = [Var | DupVars0],
map.det_update(Zone, DupVars, !ZonesToDupVars)
else
map.det_insert(Zone, [Var], !ZonesToDupVars)
).