mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-21 04:13:46 +00:00
Consider two mutually recursive procedures p and q, where p tailcalls q
but q does not tailcall p. The LLDS backend can optimize the tailcall
from p to q, but the MLDS backend cannot, because it can optimize only
*mutual* tail recursion. In such cases, and in other cases where the
MLDS cannot implement a recursive call as a tail call even though the
LLDS backend can, add to the warning message we generate a description
of the reason why the MLDS code generator cannot do what the programmer
may expect them to do.
compiler/ml_gen_info.m:
Include in the state of the MLDS code generator tail-call-related
information not just about all the procedures in the current TSCC,
but about all the procedures in the current SCC. And instead of
storing warning messages about non-tail recursive calls in the code
generator state, store a list of the non-tail recursive calls themselves.
These two changes together allow us to gather a description of all
the non-tail recursive calls before we generate even the first warning.
This should allow a later to use this information to generate messages
such as "the recursive call from p to q here cannot be optimized
because the recursive call from q to p at this *other* context
cannot be optimized".
Make the names of some types and function symbols clearer.
compiler/ml_call_gen.m:
Whenever a recursive call cannot be optimized as a tail call,
record the reason behind that fact.
Use pred_proc_ids instead of separate pred_ids and proc_ids,
since this simplifies the code and should speed paramater passing.
compiler/ml_proc_gen.m:
Pass tail-call-related information about the procedures of the SCC along
as we generate code for the SCC's procedures.
Once we have generated code for all of the SCC's procedures,
turn the final list of the non-tail calls in the SCC into a list
of warnings for them.
compiler/options.m:
doc/user_guide.texi:
Add a compiler option that controls whether we report as non-tail
calls recursive calls that *obviously* cannot be tail calls, because
they are followed by other recursive calls. The standard example
is the first recursive call in qsort.
A comment by Paul has long called for such an option, and this diff
touches the same code anyway.
Fix an unrelated old blemish: document both of the old options
--warn-non-tail-recursion-{self,mutual}, but in a commented out form,
since they are internal-use options. Before this diff, only one was
documented, and only user_guide.texi.
compiler/mark_tail_calls.m:
Add parameters to the predicates that generate warnings that specify
why the recursive call cannot be optimized as a tail call (describing
the reason if it is a result of a limitation in the compiler, and
not a problem in the program being compiled), and whether the call
is obviously a non-tail call.
When marking a call as recursive, but the recursive call is obviously
not a tail call, mark it as such using a new goal feature. The MLDS
backend needs this to allow it to filter warnings for obviousness
the same way as mark_tail_calls.m itself.
compiler/hlds_goal.m:
Add the new goal feature mentioned above.
compiler/ml_closure_gen.m:
compiler/ml_tailcall.m:
compiler/rtti_to_mlds.m:
compiler/saved_vars.m:
Conform to the changes above.
tests/invalid/require_tailrec_1.err_exp2:
tests/invalid/require_tailrec_2.err_exp2:
tests/invalid/require_tailrec_3.err_exp2:
Add the expected warnings from the MLDS code generator.
tests/invalid/Mercury.options:
Specify -E for one of the tests above, to test the handling of the
verbose-only part of the warnings.
tests/EXPECT_FAIL_TESTS.hlc.gc:
Do not expect tests/invalid/require_tailrec_[123] to fail
in grade hlc.gc anymore.
0 lines
0 B
Plaintext
0 lines
0 B
Plaintext
The file is empty.