mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-15 17:33:38 +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.
179 lines
6.9 KiB
Mathematica
179 lines
6.9 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=4 sw=4 et
|
|
%---------------------------------------------------------------------------%
|
|
% Copyright (C) 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: warn_unread_modules.m.
|
|
%
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- module parse_tree.warn_unread_modules.
|
|
:- interface.
|
|
|
|
:- import_module mdbcomp.
|
|
:- import_module mdbcomp.sym_name.
|
|
:- import_module parse_tree.error_spec.
|
|
|
|
:- import_module list.
|
|
:- import_module set_tree234.
|
|
|
|
:- pred warn_about_any_unread_modules_with_read_ancestors(
|
|
set_tree234(module_name)::in, set_tree234(module_name)::in,
|
|
list(error_spec)::in, list(error_spec)::out) is det.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module libs.
|
|
:- import_module libs.options.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
warn_about_any_unread_modules_with_read_ancestors(ReadModules, UnreadModules,
|
|
!Specs) :-
|
|
set_tree234.to_sorted_list(UnreadModules, UnreadModuleList),
|
|
find_read_ancestors_of_unread_modules(ReadModules, UnreadModuleList,
|
|
set_tree234.init, Parents, set_tree234.init, Ancestors,
|
|
set_tree234.init, BadUnreads),
|
|
set_tree234.to_sorted_list(BadUnreads, BadUnreadList),
|
|
(
|
|
BadUnreadList = []
|
|
;
|
|
BadUnreadList = [_ | _],
|
|
BadUnreadModulePieces = list.map(wrap_module_name, BadUnreadList),
|
|
list.intersperse(nl, BadUnreadModulePieces, BadUnreadModuleListPieces),
|
|
TheModules = choose_number(BadUnreadList, "the module", "the modules"),
|
|
BadUnreadPieces =
|
|
[words(TheModules), nl_indent_delta(1), blank_line] ++
|
|
BadUnreadModuleListPieces ++ [nl_indent_delta(-1), blank_line],
|
|
|
|
set_tree234.to_sorted_list(Parents, ParentList),
|
|
set_tree234.to_sorted_list(Ancestors, AncestorList),
|
|
ParentModulePieces = list.map(wrap_module_name, ParentList),
|
|
AncestorModulePieces = list.map(wrap_module_name, AncestorList),
|
|
(
|
|
ParentModulePieces = [],
|
|
ParentPieces = []
|
|
;
|
|
ParentModulePieces = [_ | TailParentModulePieces],
|
|
(
|
|
TailParentModulePieces = [],
|
|
ParentWords = "a parent module,"
|
|
;
|
|
TailParentModulePieces = [_ | _],
|
|
ParentWords = "parent modules,"
|
|
),
|
|
list.intersperse(nl, ParentModulePieces, ParentModuleListPieces),
|
|
ParentPieces =
|
|
[words(ParentWords), words("specifically"),
|
|
nl_indent_delta(1), blank_line] ++
|
|
ParentModuleListPieces ++ [nl_indent_delta(-1), blank_line]
|
|
),
|
|
(
|
|
AncestorModulePieces = [],
|
|
AncestorPieces = []
|
|
;
|
|
AncestorModulePieces = [_ | TailAncestorModulePieces],
|
|
(
|
|
TailAncestorModulePieces = [],
|
|
AncestorWords = "an ancestor module,"
|
|
;
|
|
TailAncestorModulePieces = [_ | _],
|
|
AncestorWords = "ancestor modules,"
|
|
),
|
|
list.intersperse(nl, AncestorModulePieces,
|
|
AncestorModuleListPieces),
|
|
AncestorPieces0 =
|
|
[words(AncestorWords), words("specifically"),
|
|
nl_indent_delta(1), blank_line] ++
|
|
AncestorModuleListPieces ++ [nl_indent_delta(-1), blank_line],
|
|
(
|
|
ParentModulePieces = [],
|
|
AncestorPieces = AncestorPieces0
|
|
;
|
|
ParentModulePieces = [_ | _],
|
|
AncestorPieces = [words("and") | AncestorPieces0]
|
|
)
|
|
),
|
|
Pieces =
|
|
[words("Warning:")] ++ BadUnreadPieces ++
|
|
[words("which the compiler could not find"),
|
|
words("in the current directory,"), words("have")] ++
|
|
ParentPieces ++ AncestorPieces ++
|
|
[words("which the compiler *did* find in the current directory."),
|
|
blank_line,
|
|
words("This usually indicates that the Mercury.modules file,"),
|
|
words("which contains the module name to source file name map,"),
|
|
words("is either missing or out-of-date."),
|
|
words("You need to rebuild it."),
|
|
words("This is usually done using a command such as"),
|
|
quote("mmc -f *.m"), suffix("."), nl],
|
|
Severity = severity_warning(warn_missing_descendant_modules),
|
|
Spec = no_ctxt_spec($pred, Severity, phase_read_files, Pieces),
|
|
!:Specs = [Spec | !.Specs]
|
|
).
|
|
|
|
:- func wrap_module_name(module_name) = format_piece.
|
|
|
|
wrap_module_name(ModuleName) = fixed(sym_name_to_string(ModuleName)).
|
|
|
|
:- pred find_read_ancestors_of_unread_modules(set_tree234(module_name)::in,
|
|
list(module_name)::in,
|
|
set_tree234(module_name)::in, set_tree234(module_name)::out,
|
|
set_tree234(module_name)::in, set_tree234(module_name)::out,
|
|
set_tree234(module_name)::in, set_tree234(module_name)::out) is det.
|
|
|
|
find_read_ancestors_of_unread_modules(_ReadModules, [],
|
|
!Parents, !Ancestors, !BadUnreads).
|
|
find_read_ancestors_of_unread_modules(ReadModules,
|
|
[UnreadModule | UnreadModules],
|
|
!Parents, !Ancestors, !BadUnreads) :-
|
|
(
|
|
UnreadModule = unqualified(_)
|
|
;
|
|
UnreadModule = qualified(ParentModule, _),
|
|
( if
|
|
find_first_read_ancestor(ReadModules, ParentModule, parent,
|
|
AncestorModule, PoA)
|
|
then
|
|
set_tree234.insert(UnreadModule, !BadUnreads),
|
|
(
|
|
PoA = parent,
|
|
set_tree234.insert(AncestorModule, !Parents)
|
|
;
|
|
PoA = ancestor,
|
|
set_tree234.insert(AncestorModule, !Ancestors)
|
|
)
|
|
else
|
|
true
|
|
)
|
|
),
|
|
find_read_ancestors_of_unread_modules(ReadModules, UnreadModules,
|
|
!Parents, !Ancestors, !BadUnreads).
|
|
|
|
:- type parent_or_ancestor
|
|
---> parent
|
|
; ancestor.
|
|
|
|
:- pred find_first_read_ancestor(set_tree234(module_name)::in,
|
|
module_name::in, parent_or_ancestor::in,
|
|
module_name::out, parent_or_ancestor::out) is semidet.
|
|
|
|
find_first_read_ancestor(ReadModules, Module, CurPoA, AncestorModule, PoA) :-
|
|
( if set_tree234.contains(ReadModules, Module) then
|
|
AncestorModule = Module,
|
|
PoA = CurPoA
|
|
else
|
|
Module = qualified(ParentModule, _),
|
|
find_first_read_ancestor(ReadModules, ParentModule, ancestor,
|
|
AncestorModule, PoA)
|
|
).
|
|
|
|
%---------------------------------------------------------------------------%
|
|
:- end_module parse_tree.warn_unread_modules.
|
|
%---------------------------------------------------------------------------%
|