mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-15 09:23:44 +00:00
The objective of this step is two-fold:
- to fix --inhibit-warnings, making it shut up all warning
and informational messages; and
- to ensure that it *stays* fixed, even when after new diagnostics
are added.
As part of this fix, this diff adds a whole bunch of new warning
options, in order to control the warnings that previously were
not controlled by any option. (There was no need for new
informational options.)
As it happens, we have long used severity_informational for messages
that did not report any information about the code being compiled,
but to report actions that the compiler was taking. Create a new
option category, oc_report, for the new options that now control
those diagnostics.
---------------------
compiler/error_spec.m:
Change severity_warning and severity_informational to take an option
as as argument. The semantics is that the diagnostic in which
the severity occurs is conditional on that option, meaning that
it is printed only if that option is set to "yes".
Delete the severity_conditional function symbol from the severity
type, since the mechanism just above handles its only use case.
Define subtypes to represent error_specs in a standard form.
compiler/error_sort.m:
Provide operations to convert error specs into their standard form.
Make the sorting operation itself operate on the standard form.
compiler/write_error_spec.m:
Convert error_specs to standard form before writing them out,
in order to avoid duplicating the code for their standardization.
Change the code that writes out error_specs to operate on the
standard form. Implement the test implicit in the warning and
and informational severities in this code.
compiler/error_util.m:
compiler/compiler_util.m:
Delete operations that do not make sense with the new severity type.
---------------------
compiler/options.m:
Add new options to control all the previously-uncontrolled
warning and informational messages.
NEWS.md:
Announce the *public* new options.
compiler/option_categories.m:
compiler/print_help.m:
Add the new option category, and fake-include it in the help text
and the user guide. (The inclusion is fake because none of the
options in the new category are user visible, meaning the section
containing them is not visible either.)
---------------------
compiler/det_infer_goal.m:
Start a severity warning diagnostic with "Warning:"
instead of "Error:".
compiler/mark_trace_goals.m:
Fix an incorrect error message.
compiler/purity.m:
Replace a correct/incorrect color pair with two inconsistent colors,
because there is a reasonable probability of each one being right.
---------------------
compiler/accumulator.m:
compiler/add_clause.m:
compiler/add_mode.m:
compiler/add_pragma.m:
compiler/add_pragma_tabling.m:
compiler/add_pred.m:
compiler/add_type.m:
compiler/check_module_interface.m:
compiler/check_type_inst_mode_defns.m:
compiler/check_typeclass.m:
compiler/color_schemes.m:
compiler/common.m:
compiler/convert_import_use.m:
compiler/convert_parse_tree.m:
compiler/dead_proc_elim.m:
compiler/det_check_proc.m:
compiler/det_check_switch.m:
compiler/det_infer_goal.m:
compiler/du_type_layout.m:
compiler/format_call_errors.m:
compiler/grab_modules.m:
compiler/hlds_call_tree.m:
compiler/inst_check.m:
compiler/introduce_parallelism.m:
compiler/make_hlds_error.m:
compiler/make_hlds_warn.m:
compiler/mark_tail_calls.m:
compiler/mark_trace_goals.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_make_hlds.m:
compiler/mode_errors.m:
compiler/modes.m:
compiler/module_qual.qual_errors.m:
compiler/opt_deps_spec.m:
compiler/options_file.m:
compiler/parse_goal.m:
compiler/post_term_analysis.m:
compiler/post_typecheck.m:
compiler/pre_typecheck.m:
compiler/purity.m:
compiler/read_modules.m:
compiler/recompilation.check.m:
compiler/simplify_goal.m:
compiler/simplify_goal_call.m:
compiler/simplify_goal_disj.m:
compiler/simplify_goal_ite.m:
compiler/split_parse_tree_src.m:
compiler/state_var.m:
compiler/stratify.m:
compiler/style_checks.m:
compiler/superhomogeneous.m:
compiler/table_gen.m:
compiler/term_constr_errors.m:
compiler/term_errors.m:
compiler/termination.m:
compiler/typecheck_clauses.m:
compiler/typecheck_error_overload.m:
compiler/typecheck_error_undef.m:
compiler/typecheck_errors.m:
compiler/typecheck_msgs.m:
compiler/unused_args.m:
compiler/unused_imports.m:
compiler/warn_unread_modules.m:
compiler/write_module_interface_files.m:
Conform to the changes above, mostly by either
- adding an option to all warning and informational messages,
sometimes using existing warning options and sometimes new ones,
or
- turning already explicitly-conditional-on-an-option messages
into implicitly-conditional-on-that-option messages.
---------------------
tests/invalid/one_member.m:
Conform to the change in det_infer_goal.m.
tests/invalid/require_tailrec_1.err_exp:
tests/invalid/require_tailrec_2.err_exp:
Actually obey the options for these modules in Mercury.options.
tests/invalid_purity/purity.err_exp:
tests/warnings/purity_warnings.err_exp:
Conform to the change in purity.m.
tests/warnings/moved_trace_goal.err_exp:
Conform to the change in mark_trace_goals.m.
tests/warnings/help_text.err_exp:
Expect the documentation of all the new options.
322 lines
12 KiB
Mathematica
322 lines
12 KiB
Mathematica
%-----------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=4 sw=4 et
|
|
%-----------------------------------------------------------------------------%
|
|
% Copyright (C) 2002, 2005-2007, 2010-2011 The University of Melbourne.
|
|
% Copyright (C) 2014-2015, 2017-2018, 2020, 2022, 2024-2025 The Mercury team.
|
|
% This file may only be copied under the terms of the GNU General
|
|
% Public License - see the file COPYING in the Mercury distribution.
|
|
%-----------------------------------------------------------------------------%
|
|
%
|
|
% File: term_constr_errors.m.
|
|
% Main author: juliensf.
|
|
%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- module transform_hlds.term_constr_errors.
|
|
:- interface.
|
|
|
|
:- import_module hlds.
|
|
:- import_module hlds.hlds_module.
|
|
:- import_module hlds.hlds_pred.
|
|
:- import_module parse_tree.
|
|
:- import_module parse_tree.error_spec.
|
|
:- import_module parse_tree.prog_data.
|
|
|
|
:- import_module list.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%
|
|
% Termination 2 Errors
|
|
%
|
|
|
|
% The termination errors are all in reference to possible non-termination.
|
|
% While it is possible for pass 1 to go amiss the worst that will happen
|
|
% (barring an abnormal abort) is that the size of the arguments will be
|
|
% unconstrained.
|
|
|
|
:- type term2_error_kind
|
|
---> imported_pred
|
|
% Termination could not be proved because it depends upon
|
|
% information from another module and that information is not
|
|
% available.
|
|
|
|
; can_loop_proc_called(pred_proc_id, pred_proc_id)
|
|
% Termination could not be proved because the procedure called
|
|
% another procedure that may not terminate.
|
|
|
|
; cond_not_satisfied
|
|
% Termination could not be proved because no set of decreasing
|
|
% argument could be found.
|
|
|
|
; horder_call
|
|
% Termination could not be proved because the procedure makes
|
|
% higher-order calls.
|
|
|
|
; does_not_term_pragma(pred_id)
|
|
% Termination could not be proved because the procedure was marked
|
|
% with a `does_not_terminate' pragma.
|
|
|
|
; foreign_proc_called(pred_proc_id).
|
|
% Termination depends upon the properties of a piece of foreign
|
|
% code that cannot be established as terminating.
|
|
|
|
:- type term2_error
|
|
---> term2_error(prog_context, term2_error_kind).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- pred maybe_report_term2_errors(module_info::in, scc::in,
|
|
list(term2_error)::in,
|
|
list(error_spec)::in, list(error_spec)::out) is det.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module hlds.hlds_error_util.
|
|
:- import_module hlds.hlds_markers.
|
|
:- import_module libs.
|
|
:- import_module libs.globals.
|
|
:- import_module libs.options.
|
|
:- import_module transform_hlds.term_util.
|
|
|
|
:- import_module bool.
|
|
:- import_module cord.
|
|
:- import_module int.
|
|
:- import_module maybe.
|
|
:- import_module require.
|
|
:- import_module set.
|
|
:- import_module string.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
maybe_report_term2_errors(ModuleInfo, SCC, Errors, !Specs) :-
|
|
decide_what_term2_errors_to_report(ModuleInfo, SCC, Errors,
|
|
MaybeErrorsToReport),
|
|
(
|
|
MaybeErrorsToReport = no
|
|
;
|
|
MaybeErrorsToReport = yes(ErrorsToReport),
|
|
report_term2_errors(ModuleInfo, SCC, ErrorsToReport, !Specs)
|
|
).
|
|
|
|
:- pred decide_what_term2_errors_to_report(module_info::in,
|
|
scc::in, list(term2_error)::in, maybe(list(term2_error))::out) is det.
|
|
|
|
decide_what_term2_errors_to_report(ModuleInfo, SCC, Errors,
|
|
MaybeErrorsToReport) :-
|
|
% NOTE The code of this predicate follows the same logic as the
|
|
% code of decide_what_term_errors_to_report in termination.m.
|
|
% Although there are differences in the data types they operate on
|
|
% and the options they consult, any changes here probably require
|
|
% corresponding changes there as well.
|
|
|
|
% The logic of this code is documented in comments in
|
|
% decide_what_term_errors_to_report.
|
|
|
|
module_info_get_globals(ModuleInfo, Globals),
|
|
globals.lookup_bool_option(Globals, termination2_check, NormalErrors),
|
|
globals.lookup_bool_option(Globals, termination2_check_verbose,
|
|
VerboseErrors),
|
|
( if
|
|
IsCheckTerm =
|
|
( pred(PPId::in) is semidet :-
|
|
module_info_pred_proc_info(ModuleInfo, PPId, PredInfo, _),
|
|
not pred_info_is_imported(PredInfo),
|
|
pred_info_get_markers(PredInfo, Markers),
|
|
marker_is_present(Markers, marker_check_termination)
|
|
),
|
|
set.filter(IsCheckTerm, SCC, CheckTermPPIds),
|
|
set.is_non_empty(CheckTermPPIds)
|
|
then
|
|
MaybeErrorsToReport = yes(Errors)
|
|
else if
|
|
IsNonImported =
|
|
( pred(PPId::in) is semidet :-
|
|
module_info_pred_proc_info(ModuleInfo, PPId, PredInfo, _),
|
|
not pred_info_is_imported(PredInfo)
|
|
),
|
|
set.filter(IsNonImported, SCC, NonImportedPPIds),
|
|
set.is_non_empty(NonImportedPPIds)
|
|
then
|
|
(
|
|
VerboseErrors = yes,
|
|
MaybeErrorsToReport = yes(Errors)
|
|
;
|
|
VerboseErrors = no,
|
|
(
|
|
NormalErrors = yes,
|
|
IsDirect =
|
|
( pred(Error::in) is semidet :-
|
|
Error = term2_error(_, ErrorKind),
|
|
term2_error_kind_is_direct(ErrorKind) = yes
|
|
),
|
|
list.filter(IsDirect, Errors, DirectErrors),
|
|
(
|
|
DirectErrors = [],
|
|
MaybeErrorsToReport = yes(Errors)
|
|
;
|
|
DirectErrors = [_ | _],
|
|
MaybeErrorsToReport = yes(DirectErrors)
|
|
)
|
|
;
|
|
NormalErrors = no,
|
|
MaybeErrorsToReport = no
|
|
)
|
|
)
|
|
else
|
|
MaybeErrorsToReport = no
|
|
).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- pred report_term2_errors(module_info::in, scc::in,
|
|
list(term2_error)::in, list(error_spec)::in, list(error_spec)::out) is det.
|
|
|
|
report_term2_errors(ModuleInfo, SCC, Errors, !Specs) :-
|
|
get_context_from_scc(ModuleInfo, SCC, Context),
|
|
( if set.is_singleton(SCC, PPId) then
|
|
Pieces0 = [words("Termination of")],
|
|
ProcName = describe_qual_proc_name(ModuleInfo, PPId),
|
|
Pieces1 = Pieces0 ++ ProcName,
|
|
Single = yes(PPId)
|
|
else
|
|
Pieces0 = [words("Termination of the"),
|
|
words("mutually recursive procedures")],
|
|
ProcNames = describe_several_proc_names(ModuleInfo, no,
|
|
should_module_qualify, set.to_sorted_list(SCC)),
|
|
Pieces1 = Pieces0 ++ ProcNames,
|
|
Single = no
|
|
),
|
|
(
|
|
Errors = [],
|
|
Pieces2 = [words("not proven, for unknown reason(s).")],
|
|
ReasonMsgsCord = cord.init
|
|
;
|
|
Errors = [Error],
|
|
Pieces2 = [words("not proven for the following reason:")],
|
|
describe_term2_error(ModuleInfo, Single, no, Error,
|
|
cord.init, ReasonMsgsCord)
|
|
;
|
|
Errors = [_, _ | _],
|
|
Pieces2 = [words("not proven for the following reasons:")],
|
|
describe_term2_errors(ModuleInfo, Single, 1, Errors,
|
|
cord.init, ReasonMsgsCord)
|
|
),
|
|
ReasonMsgs = cord.list(ReasonMsgsCord),
|
|
Msgs = [simple_msg(Context, [always(Pieces1 ++ Pieces2)]) | ReasonMsgs],
|
|
Severity = severity_warning(warn_requested_by_option),
|
|
Spec = error_spec($pred, Severity, phase_termination_analysis, Msgs),
|
|
!:Specs = [Spec | !.Specs].
|
|
|
|
:- pred describe_term2_errors(module_info::in, maybe(pred_proc_id)::in,
|
|
int::in, list(term2_error)::in,
|
|
cord(error_msg)::in, cord(error_msg)::out) is det.
|
|
|
|
describe_term2_errors(_, _, _, [], !ReasonMsgsCord).
|
|
describe_term2_errors(ModuleInfo, Single, ErrNum0, [Error | Errors],
|
|
!ReasonMsgsCord) :-
|
|
describe_term2_error(ModuleInfo, Single, yes(ErrNum0), Error,
|
|
!ReasonMsgsCord),
|
|
describe_term2_errors(ModuleInfo, Single, ErrNum0 + 1, Errors,
|
|
!ReasonMsgsCord).
|
|
|
|
:- pred describe_term2_error(module_info::in, maybe(pred_proc_id)::in,
|
|
maybe(int)::in, term2_error::in,
|
|
cord(error_msg)::in, cord(error_msg)::out) is det.
|
|
|
|
describe_term2_error(ModuleInfo, Single, MaybeErrorNum, Error,
|
|
!ReasonMsgsCord) :-
|
|
Error = term2_error(Context, ErrorKind),
|
|
term2_error_kind_description(ModuleInfo, Single, ErrorKind, Pieces0),
|
|
(
|
|
MaybeErrorNum = yes(N),
|
|
string.int_to_string(N, Nstr),
|
|
Preamble = "Reason " ++ Nstr ++ ":",
|
|
Pieces = [fixed(Preamble) | Pieces0]
|
|
;
|
|
MaybeErrorNum = no,
|
|
Pieces = Pieces0
|
|
),
|
|
ReasonMsg = error_msg(yes(Context), always_treat_as_first, 0u,
|
|
[always(Pieces)]),
|
|
!:ReasonMsgsCord = cord.snoc(!.ReasonMsgsCord, ReasonMsg).
|
|
|
|
:- pred term2_error_kind_description(module_info::in, maybe(pred_proc_id)::in,
|
|
term2_error_kind::in, list(format_piece)::out) is det.
|
|
|
|
term2_error_kind_description(ModuleInfo, Single, Error, Pieces) :-
|
|
(
|
|
Error = cond_not_satisfied,
|
|
Pieces = [words("The termination condition"),
|
|
words("is not satisfiable."), nl]
|
|
;
|
|
Error = imported_pred,
|
|
Pieces = [words("It contains one or more"),
|
|
words("predicates and/or functions"),
|
|
words("imported from another module."), nl]
|
|
;
|
|
Error = can_loop_proc_called(CallerPPId, CalleePPId),
|
|
(
|
|
Single = yes(PPId),
|
|
expect(unify(PPId, CallerPPId), $pred, "caller outside this SCC"),
|
|
Piece1 = [words("It")]
|
|
;
|
|
Single = no,
|
|
ProcName = describe_qual_proc_name(ModuleInfo, CallerPPId),
|
|
Piece1 = ProcName
|
|
),
|
|
Piece2 = words("calls"),
|
|
CalleePiece = describe_qual_proc_name(ModuleInfo, CalleePPId),
|
|
Pieces3 = [words("which could not be proven to terminate."), nl],
|
|
Pieces = Piece1 ++ [Piece2] ++ CalleePiece ++ Pieces3
|
|
;
|
|
Error = horder_call,
|
|
Pieces = [words("It contains a higher-order call."), nl]
|
|
;
|
|
Error = does_not_term_pragma(PredId),
|
|
Pieces1 = [words("There is a"), pragma_decl("does_not_terminate"),
|
|
words("declaration for")],
|
|
(
|
|
Single = yes(PPId),
|
|
PPId = proc(SCCPredId, _),
|
|
expect(unify(PredId, SCCPredId), $pred,
|
|
"does not terminate pragma outside this SCC"),
|
|
Pieces2 = [words("it."), nl]
|
|
;
|
|
Single = no,
|
|
PredDesc = describe_qual_pred_name(ModuleInfo, PredId),
|
|
Pieces2 = PredDesc ++ [suffix("."), nl]
|
|
),
|
|
Pieces = Pieces1 ++ Pieces2
|
|
;
|
|
Error = foreign_proc_called(PPId),
|
|
Name = describe_qual_proc_name(ModuleInfo, PPId),
|
|
Pieces = [words("There is a call the foreign procedure")] ++
|
|
Name ++ [words("which is not known to terminate."), nl]
|
|
).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- func term2_error_kind_is_direct(term2_error_kind) = bool.
|
|
|
|
term2_error_kind_is_direct(ErrorKind) = IsDirect :-
|
|
(
|
|
( ErrorKind = cond_not_satisfied
|
|
; ErrorKind = foreign_proc_called(_)
|
|
),
|
|
IsDirect = yes
|
|
;
|
|
( ErrorKind = imported_pred
|
|
; ErrorKind = horder_call
|
|
; ErrorKind = does_not_term_pragma(_)
|
|
; ErrorKind = can_loop_proc_called(_, _)
|
|
),
|
|
IsDirect = no
|
|
).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
:- end_module transform_hlds.term_constr_errors.
|
|
%-----------------------------------------------------------------------------%
|