mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-19 03:13:40 +00:00
Often a procedure whose job is to verify an invariant or otherwise help with
debugging will be private to its defining module, and will be called only
from conditionally compiled trace goal scopes. If the trace goal's condition
is false, then the procedure will have no calls to it left by the time
we invoke dead_proc_elim. However, any warning that the compiler could print
to the effect that "the procedure is never called" would be incorrect
from the programmer's point of view, even though it would be correct
from the code generator's point of view.
compiler/simplify_goal_scope.m:
When deleting a trace goal scope because it is conditionally compiled
and its condition is false, compute the set of procedures called in
the deleted goal and record that set in a new slot of the simplify_info.
compiler/simplify_info.m:
Define a new slot for that purpose.
compiler/simplify_proc.m:
When we have finished processing a procedure, add the procedure ids
in the new slot of the simplify_info to a new slot of the procedure's
proc_info.
compiler/hlds_pred.m:
Define a new slot in the proc_info (actually, proc_sub_info)
for that purpose.
compiler/dead_proc_elim.m:
When we call dead proc elimination because we want to generate warnings,
treat the procedures named in these proc_info slots as if they were
actually called (since the source code actually contains calls to them).
When we call dead proc elimination because we want to delete unused
procedures from the HLDS, because we don't want to generate code for them,
we *don't* want to treat the appearance of a procedure id in this slot
as a call. We now therefore provide two separate predicates to call:
one (dead_proc_elim) that deletes procedures from the HLDS but returns
no warnings, and another (dead_proc_warn) that generates warnings
but leaves the HLDS unchanged. Besides the different in their
signatures, these two top level predicates use slightly different
criteria to decide whether a procedure is dead or not. (No current caller
wants both an updated HLDS *and* warnings. If new callers do, they will
have to call both predicates. This will find the set of called procedures
twice, but since their criteria of what they count as "called" will be
different, the set of "called" procedures they compute could differ.)
Parameterize the code that computes the set of needed entities
to allow it to be used for both purposes.
Split the old code that used to use the results of that analysis
to both delete procedures and to generate warnings for such deletions.
There is now one copy specialized for deleting unused procedures from the
HLDS, and one copy specialized for generating warnings. The two don't
actually have that much in common.
compiler/deep_profiling.m:
compiler/mercury_compile_middle_passes.m:
Update all the places that used to call dead proc elimination
to call instead one of its two replacement predicates.
compiler/hlds_out_pred.m:
Dump the new field in the proc_info if it is not empty.
tests/warnings/warn_dead_proc_trace.{m,exp}:
A new test case to test the new functionality.
tests/warnings/Mercury.options:
tests/warnings/Mmakefile:
Enable the new test case.
2 lines
78 B
Plaintext
2 lines
78 B
Plaintext
warn_dead_procs_trace.m:040: Warning: predicate `t'/2 mode 0 is never called.
|