Files
mercury/tests/invalid/bad_consider_used.m
Zoltan Somogyi 5251d1fdd6 Add `:- pragma consider_used(predname/arity)'.
Sometimes, one wants to keep some predicates around even if they are not
currently being used. Adding this pragma for such a predicate will shut up
dead procedure/predicate warnings both for the named predicate and for the
other predicates it calls, both directly and indirectly.

With two of these pragmas added to compiler/stratify.m, the number of
predicates being reported as dead goes from 25 to 0.

compiler/prog_item.m:
    Define the new pragma.

compiler/prog_io_pragma.m:
    Parse the new pragma.

compiler/parse_tree_out_pragma.m:
    Write out the new pragma, if needed.

compiler/add_pragma.m:
    Add the new pragma to the HLDS in the form of a marker on the named
    predicate.

compiler/hlds_pred.m:
    Define that marker.

compiler/dead_proc_elim.m:
    If a predicate has that marker, consider all its procedures to be live.

compiler/comp_unit_interface.m:
compiler/equiv_type.m:
compiler/get_dependencies.m:
compiler/hlds_out_pred.m:
compiler/intermod.m:
compiler/item_util.m:
compiler/make_hlds_separate_items.m:
compiler/module_qual.qual_errors.m:
compiler/module_qual.qualify_items.m:
compiler/prog_item_stats.m:
compiler/recompilation.version.m:
compiler/table_gen.m:
compiler/write_module_interface_files.m:
    Conform to the changes above.

tests/invalid/bad_consider_used.{m,err_exp}:
    New test case to test the handling of invalid consider_used pragmas.

tests/invalid/Mmakefile:
    Add the new test case.
2015-12-14 11:36:43 +11:00

38 lines
701 B
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
:- module bad_consider_used.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module int.
main(!IO) :-
( if p(1, B) then
io.write_int(B, !IO),
io.nl(!IO)
else
io.write_string("p failed\n", !IO)
).
:- pred p(int::in, int::out) is semidet.
p(A, B) :-
A > 10,
B = A + 1.
:- pred q(int::in, int::out) is semidet.
:- pragma consider_used(q/3).
:- pragma consider_used(g/2).
q(A, B) :-
A > 20,
B = A + 2.