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.
254 lines
10 KiB
Mathematica
254 lines
10 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=4 sw=4 et
|
|
%---------------------------------------------------------------------------%
|
|
% Copyright (C) 1993-2012 The University of Melbourne.
|
|
% Copyright (C) 2014-2021, 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.
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- module check_hlds.typecheck_msgs.
|
|
:- 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 list.
|
|
:- import_module set_tree234.
|
|
|
|
:- func typecheck_report_max_iterations_exceeded(int) = error_spec.
|
|
|
|
% Construct the inferred `pred' or `func' declarations for a list of
|
|
% predicates. Don't construct declarations for the inferred types
|
|
% of predicates that represent assertions.
|
|
%
|
|
:- pred construct_type_inference_messages(module_info::in,
|
|
set_tree234(pred_id)::in, list(pred_id)::in,
|
|
list(error_spec)::in, list(error_spec)::out) is det.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module hlds.hlds_markers.
|
|
:- import_module hlds.pred_table.
|
|
:- import_module libs.
|
|
:- import_module libs.options.
|
|
:- import_module mdbcomp.
|
|
:- import_module mdbcomp.prim_data.
|
|
:- import_module mdbcomp.sym_name.
|
|
:- import_module parse_tree.parse_tree_out_pred_decl.
|
|
:- import_module parse_tree.parse_tree_out_type.
|
|
:- import_module parse_tree.prog_data.
|
|
:- import_module parse_tree.prog_type.
|
|
:- import_module parse_tree.prog_util.
|
|
|
|
:- import_module edit_seq.
|
|
:- import_module maybe.
|
|
:- import_module string.
|
|
:- import_module varset.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
typecheck_report_max_iterations_exceeded(MaxIterations) = Spec :-
|
|
Pieces = [words("Type inference iteration limit exceeded."),
|
|
words("This probably indicates that your program has a type error."),
|
|
words("You should declare the types explicitly."),
|
|
words("(The current limit is"), int_fixed(MaxIterations),
|
|
words("iterations."),
|
|
words("You can use the"), quote("--type-inference-iteration-limit"),
|
|
words("option to increase the limit)."), nl],
|
|
Spec = no_ctxt_spec($pred, severity_error, phase_type_check,
|
|
Pieces).
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
construct_type_inference_messages(_, _, [], !Specs).
|
|
construct_type_inference_messages(ModuleInfo, ValidPredIdSet,
|
|
[PredId | PredIds], !Specs) :-
|
|
module_info_pred_info(ModuleInfo, PredId, PredInfo),
|
|
pred_info_get_markers(PredInfo, Markers),
|
|
( if
|
|
marker_is_present(Markers, marker_infer_type),
|
|
set_tree234.contains(ValidPredIdSet, PredId),
|
|
not pred_info_is_promise(PredInfo, _)
|
|
then
|
|
Spec = construct_type_inference_message(ModuleInfo, PredId, PredInfo),
|
|
!:Specs = [Spec | !.Specs]
|
|
else
|
|
true
|
|
),
|
|
construct_type_inference_messages(ModuleInfo, ValidPredIdSet,
|
|
PredIds, !Specs).
|
|
|
|
% Construct a message containing the inferred `pred' or `func' declaration
|
|
% for a single predicate.
|
|
%
|
|
:- func construct_type_inference_message(module_info, pred_id, pred_info)
|
|
= error_spec.
|
|
|
|
construct_type_inference_message(ModuleInfo, PredId, PredInfo) = Spec :-
|
|
PredName = pred_info_name(PredInfo),
|
|
PredOrFunc = pred_info_is_pred_or_func(PredInfo),
|
|
UnqualPredSymName = unqualified(PredName),
|
|
pred_info_get_context(PredInfo, Context),
|
|
pred_info_get_arg_types(PredInfo, VarSet, ExistQVars, Types0),
|
|
strip_module_names_from_type_list(strip_builtin_module_name,
|
|
set_default_func, Types0, Types),
|
|
pred_info_get_class_context(PredInfo, ClassContext),
|
|
pred_info_get_purity(PredInfo, Purity),
|
|
MaybeDet = no,
|
|
VarNamePrint = print_name_only,
|
|
(
|
|
PredOrFunc = pf_predicate,
|
|
ArgTypes = Types,
|
|
MaybeReturnType = no,
|
|
TypeStr = mercury_pred_type_to_string(VarSet, VarNamePrint, ExistQVars,
|
|
UnqualPredSymName, Types, MaybeDet, Purity, ClassContext)
|
|
;
|
|
PredOrFunc = pf_function,
|
|
pred_args_to_func_args(Types, ArgTypes, ReturnType),
|
|
MaybeReturnType = yes(ReturnType),
|
|
TypeStr = mercury_func_type_to_string(VarSet, VarNamePrint, ExistQVars,
|
|
UnqualPredSymName, ArgTypes, ReturnType, MaybeDet, Purity,
|
|
ClassContext)
|
|
),
|
|
InferredPieces = [invis_order_default_start(2, ""),
|
|
words("Inferred"), words(TypeStr), nl],
|
|
|
|
module_info_get_predicate_table(ModuleInfo, PredicateTable),
|
|
ModuleName = pred_info_module(PredInfo),
|
|
QualPredSymName = qualified(ModuleName, PredName),
|
|
predicate_table_lookup_pf_sym(PredicateTable, is_fully_qualified,
|
|
PredOrFunc, QualPredSymName, AllPredIds),
|
|
list.delete_all(AllPredIds, PredId, AllOtherPredIds),
|
|
PredIsDeclared =
|
|
( pred(OtherPredId::in) is semidet :-
|
|
module_info_pred_info(ModuleInfo, OtherPredId, OtherPredInfo),
|
|
pred_info_get_markers(OtherPredInfo, OtherPredMarkers),
|
|
not marker_is_present(OtherPredMarkers, marker_infer_type)
|
|
),
|
|
list.filter(PredIsDeclared, AllOtherPredIds, AllOtherDeclaredPredIds),
|
|
(
|
|
AllOtherDeclaredPredIds = [],
|
|
Spec = spec($pred, severity_informational(inform_inferred_types),
|
|
phase_type_check, Context, InferredPieces)
|
|
;
|
|
AllOtherDeclaredPredIds = [_ | _],
|
|
list.map(
|
|
construct_pred_decl_diff(ModuleInfo, ArgTypes, MaybeReturnType),
|
|
AllOtherDeclaredPredIds, DiffPieceLists),
|
|
Pieces = [invis_order_default_start(2, "")] ++ InferredPieces ++
|
|
list.condense(DiffPieceLists),
|
|
Spec = spec($pred, severity_informational(inform_inferred_types),
|
|
phase_type_check, Context, Pieces)
|
|
).
|
|
|
|
:- pred construct_pred_decl_diff(module_info::in,
|
|
list(mer_type)::in, maybe(mer_type)::in, pred_id::in,
|
|
list(format_piece)::out) is det.
|
|
|
|
construct_pred_decl_diff(ModuleInfo, ActualArgTypes, MaybeActualReturnType,
|
|
OtherPredId, Pieces) :-
|
|
module_info_pred_info(ModuleInfo, OtherPredId, OtherPredInfo),
|
|
pred_info_get_arg_types(OtherPredInfo, OtherTypes),
|
|
% It would be nice if we could print the names of type variables,
|
|
% but there are two problems. The lesser problem is that the names
|
|
% may be different in the varsets of the two predicates, which may be
|
|
% confusing. The more deadly problem is that a type variable that
|
|
% exists in one of the varsets may not exist in the other.
|
|
% Therefore printing variable numbers is the best thing we can do,
|
|
% as a general case. (We *could* do better in the special case
|
|
% where neither problem arises.)
|
|
varset.init(TVarSet),
|
|
(
|
|
MaybeActualReturnType = no,
|
|
list.length(OtherTypes, OtherArity),
|
|
pred_decl_lines(TVarSet, ActualArgTypes, ActualLines),
|
|
pred_decl_lines(TVarSet, OtherTypes, OtherLines)
|
|
;
|
|
MaybeActualReturnType = yes(ActualReturnType),
|
|
pred_args_to_func_args(OtherTypes, OtherArgTypes, OtherReturnType),
|
|
list.length(OtherArgTypes, OtherArity),
|
|
func_decl_lines(TVarSet, ActualArgTypes, ActualReturnType,
|
|
ActualLines),
|
|
func_decl_lines(TVarSet, OtherArgTypes, OtherReturnType,
|
|
OtherLines)
|
|
),
|
|
EditParams = edit_params(1, 1, 2), % cost(replace) = cost(delete + insert).
|
|
find_shortest_edit_seq(EditParams, OtherLines, ActualLines, EditSeq),
|
|
find_diff_seq(OtherLines, EditSeq, DiffSeq),
|
|
DiffPieceLists = list.map(diff_to_pieces, DiffSeq),
|
|
list.condense(DiffPieceLists, DiffPieces),
|
|
Pieces = [words("The argument list difference from the arity"),
|
|
int_fixed(OtherArity), words("version is"), nl] ++ DiffPieces.
|
|
|
|
:- func diff_to_pieces(diff(string)) = list(format_piece).
|
|
|
|
diff_to_pieces(Diff) = Pieces :-
|
|
(
|
|
Diff = unchanged(Line),
|
|
Pieces = [fixed(" " ++ Line), nl]
|
|
;
|
|
Diff = deleted(Line),
|
|
Pieces0 = [fixed("- " ++ Line), nl],
|
|
Pieces = color_as_correct(Pieces0)
|
|
;
|
|
Diff = inserted(Line),
|
|
Pieces0 = [fixed("+ " ++ Line), nl],
|
|
Pieces = color_as_incorrect(Pieces0)
|
|
).
|
|
|
|
:- pred pred_decl_lines(tvarset::in, list(mer_type)::in,
|
|
list(string)::out) is det.
|
|
|
|
pred_decl_lines(TVarSet, ArgTypes, Lines) :-
|
|
( if list.split_last(ArgTypes, NonLastArgTypes, LastArgType) then
|
|
arg_decl_lines("pred", TVarSet, NonLastArgTypes, LastArgType, "",
|
|
Lines)
|
|
else
|
|
Lines = ["pred"]
|
|
).
|
|
|
|
:- pred func_decl_lines(tvarset::in, list(mer_type)::in, mer_type::in,
|
|
list(string)::out) is det.
|
|
|
|
func_decl_lines(TVarSet, ArgTypes, ReturnType, Lines) :-
|
|
ReturnTypeStr =
|
|
mercury_type_to_string(TVarSet, print_num_only, ReturnType),
|
|
ReturnTypeSuffix = " = " ++ ReturnTypeStr,
|
|
( if list.split_last(ArgTypes, NonLastArgTypes, LastArgType) then
|
|
arg_decl_lines("func", TVarSet, NonLastArgTypes, LastArgType,
|
|
ReturnTypeSuffix, Lines)
|
|
else
|
|
Lines = ["func" ++ ReturnTypeSuffix]
|
|
).
|
|
|
|
:- pred arg_decl_lines(string::in, tvarset::in,
|
|
list(mer_type)::in, mer_type::in, string::in, list(string)::out) is det.
|
|
|
|
arg_decl_lines(PredOrFuncStr, TVarSet, NonLastArgTypes, LastArgType, Suffix,
|
|
Lines) :-
|
|
NonLastArgTypeStrs = list.map(
|
|
mercury_type_to_string(TVarSet, print_num_only), NonLastArgTypes),
|
|
AddComma =
|
|
(func(NonLastArgTypeStr) = one_indent ++ NonLastArgTypeStr ++ ","),
|
|
NonLastArgTypeLines = list.map(AddComma, NonLastArgTypeStrs),
|
|
LastArgTypeStr =
|
|
mercury_type_to_string(TVarSet, print_num_only, LastArgType),
|
|
Lines = [PredOrFuncStr ++ "("] ++
|
|
NonLastArgTypeLines ++
|
|
[one_indent ++ LastArgTypeStr,
|
|
")" ++ Suffix].
|
|
|
|
:- func one_indent = string.
|
|
|
|
one_indent = " ".
|
|
|
|
%---------------------------------------------------------------------------%
|
|
:- end_module check_hlds.typecheck_msgs.
|
|
%---------------------------------------------------------------------------%
|