mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-15 01:13:30 +00:00
Reduce the number of modules that set the exit status ...
... by removing compiler_util.m from that set.
compiler/tupling.m:
Replace the only two calls to report_warning with code to return
error_specs.
compiler/mercury_compile_middle_passes.m:
Accumulate the resulting error_specs.
compiler/write_error_spec.m:
Inline the only call to record_warning_opt_table.
compiler/compiler_util.m:
Delete report_warning and record_warning_opt_table, which now have
no callers, and record_warning, which had no callers to begin with.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
% vim: ft=mercury ts=4 sw=4 et
|
||||
%-----------------------------------------------------------------------------%
|
||||
% Copyright (C) 1997-2006, 2009-2010 The University of Melbourne.
|
||||
% Copyright (C) 2014-2015, 2018, 2025 The Mercury team.
|
||||
% Copyright (C) 2014-2015, 2018, 2025-2026 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.
|
||||
%-----------------------------------------------------------------------------%
|
||||
@@ -17,12 +17,10 @@
|
||||
:- module libs.compiler_util.
|
||||
:- interface.
|
||||
|
||||
:- import_module libs.globals.
|
||||
:- import_module libs.options.
|
||||
:- import_module parse_tree.
|
||||
:- import_module parse_tree.error_spec.
|
||||
|
||||
:- import_module io.
|
||||
:- import_module list.
|
||||
:- import_module maybe.
|
||||
|
||||
@@ -55,27 +53,11 @@
|
||||
:- pred add_warning(spec_phase::in, option::in, list(format_piece)::in,
|
||||
list(error_spec)::in, list(error_spec)::out) is det.
|
||||
|
||||
%-----------------------------------------------------------------------------%
|
||||
|
||||
% Record the fact that a warning has been issued; set the exit status
|
||||
% to error if the `--halt-at-warn' option is set.
|
||||
%
|
||||
:- pred record_warning(globals::in, io::di, io::uo) is det.
|
||||
:- pred record_warning_opt_table(option_table::in, io::di, io::uo) is det.
|
||||
|
||||
% Report a warning to the specified stream, and set the exit status
|
||||
% to error if the --halt-at-warn option is set.
|
||||
%
|
||||
:- pred report_warning(io.text_output_stream::in, globals::in, string::in,
|
||||
io::di, io::uo) is det.
|
||||
|
||||
%-----------------------------------------------------------------------------%
|
||||
%-----------------------------------------------------------------------------%
|
||||
|
||||
:- implementation.
|
||||
|
||||
:- import_module bool.
|
||||
:- import_module getopt.
|
||||
|
||||
%-----------------------------------------------------------------------------%
|
||||
|
||||
@@ -96,30 +78,6 @@ add_warning(Phase, Option, Pieces, !Specs) :-
|
||||
Spec = no_ctxt_spec($pred, severity_warning(Option), Phase, Pieces),
|
||||
!:Specs = [Spec | !.Specs].
|
||||
|
||||
%-----------------------------------------------------------------------------%
|
||||
|
||||
record_warning(Globals, !IO) :-
|
||||
globals.lookup_bool_option(Globals, halt_at_warn, HaltAtWarn),
|
||||
(
|
||||
HaltAtWarn = yes,
|
||||
io.set_exit_status(1, !IO)
|
||||
;
|
||||
HaltAtWarn = no
|
||||
).
|
||||
|
||||
record_warning_opt_table(OptionTable, !IO) :-
|
||||
getopt.lookup_bool_option(OptionTable, halt_at_warn, HaltAtWarn),
|
||||
(
|
||||
HaltAtWarn = yes,
|
||||
io.set_exit_status(1, !IO)
|
||||
;
|
||||
HaltAtWarn = no
|
||||
).
|
||||
|
||||
report_warning(Stream, Globals, Message, !IO) :-
|
||||
record_warning(Globals, !IO),
|
||||
io.write_string(Stream, Message, !IO).
|
||||
|
||||
%-----------------------------------------------------------------------------%
|
||||
:- end_module libs.compiler_util.
|
||||
%-----------------------------------------------------------------------------%
|
||||
|
||||
@@ -206,7 +206,7 @@ middle_pass(ProgressStream, ErrorStream, OpModeFrontAndMiddle,
|
||||
maybe_untuple_arguments(ProgressStream, Verbose, Stats, !HLDS, !IO),
|
||||
maybe_dump_hlds(ProgressStream, !.HLDS, 133, "untupling", !DumpInfo, !IO),
|
||||
|
||||
maybe_tuple_arguments(ProgressStream, Verbose, Stats, !HLDS, !IO),
|
||||
maybe_tuple_arguments(ProgressStream, Verbose, Stats, !HLDS, !Specs, !IO),
|
||||
maybe_dump_hlds(ProgressStream, !.HLDS, 134, "tupling", !DumpInfo, !IO),
|
||||
|
||||
maybe_higher_order_or_type_spec(ProgressStream, Verbose, Stats,
|
||||
@@ -925,9 +925,10 @@ maybe_untuple_arguments(ProgressStream, Verbose, Stats, !HLDS, !IO) :-
|
||||
%---------------------------------------------------------------------------%
|
||||
|
||||
:- pred maybe_tuple_arguments(io.text_output_stream::in, bool::in, bool::in,
|
||||
module_info::in, module_info::out, io::di, io::uo) is det.
|
||||
module_info::in, module_info::out,
|
||||
list(error_spec)::in, list(error_spec)::out, io::di, io::uo) is det.
|
||||
|
||||
maybe_tuple_arguments(ProgressStream, Verbose, Stats, !HLDS, !IO) :-
|
||||
maybe_tuple_arguments(ProgressStream, Verbose, Stats, !HLDS, !Specs, !IO) :-
|
||||
module_info_get_globals(!.HLDS, Globals),
|
||||
globals.get_opt_tuple(Globals, OptTuple),
|
||||
Tuple = OptTuple ^ ot_tuple,
|
||||
@@ -935,7 +936,8 @@ maybe_tuple_arguments(ProgressStream, Verbose, Stats, !HLDS, !IO) :-
|
||||
Tuple = tuple,
|
||||
maybe_write_string(ProgressStream, Verbose, "% Tupling...\n", !IO),
|
||||
maybe_flush_output(ProgressStream, Verbose, !IO),
|
||||
tuple_arguments(ProgressStream, !HLDS, !IO),
|
||||
tuple_arguments(ProgressStream, TupleSpecs, !HLDS, !IO),
|
||||
!:Specs = TupleSpecs ++ !.Specs,
|
||||
maybe_write_string(ProgressStream, Verbose, "% done.\n", !IO),
|
||||
maybe_report_stats(ProgressStream, Stats, !IO)
|
||||
;
|
||||
|
||||
@@ -87,10 +87,13 @@
|
||||
|
||||
:- import_module hlds.
|
||||
:- import_module hlds.hlds_module.
|
||||
:- import_module parse_tree.
|
||||
:- import_module parse_tree.error_spec.
|
||||
|
||||
:- import_module io.
|
||||
:- import_module list.
|
||||
|
||||
:- pred tuple_arguments(io.text_output_stream::in,
|
||||
:- pred tuple_arguments(io.text_output_stream::in, list(error_spec)::out,
|
||||
module_info::in, module_info::out, io::di, io::uo) is det.
|
||||
|
||||
%-----------------------------------------------------------------------------%
|
||||
@@ -118,7 +121,6 @@
|
||||
:- import_module hlds.pred_name.
|
||||
:- import_module hlds.quantification.
|
||||
:- import_module libs.
|
||||
:- import_module libs.compiler_util.
|
||||
:- import_module libs.dependency_graph.
|
||||
:- import_module libs.globals.
|
||||
:- import_module libs.optimization_options.
|
||||
@@ -133,7 +135,6 @@
|
||||
:- import_module mdbcomp.read_trace_counts.
|
||||
:- import_module mdbcomp.sym_name.
|
||||
:- import_module mdbcomp.trace_counts.
|
||||
:- import_module parse_tree.
|
||||
:- import_module parse_tree.builtin_lib_types.
|
||||
:- import_module parse_tree.prog_data.
|
||||
:- import_module parse_tree.prog_mode.
|
||||
@@ -148,7 +149,6 @@
|
||||
:- import_module digraph.
|
||||
:- import_module float.
|
||||
:- import_module int.
|
||||
:- import_module list.
|
||||
:- import_module map.
|
||||
:- import_module maybe.
|
||||
:- import_module multi_map.
|
||||
@@ -165,7 +165,7 @@
|
||||
% The top level.
|
||||
%
|
||||
|
||||
tuple_arguments(ProgressStream, !ModuleInfo, !IO) :-
|
||||
tuple_arguments(ProgressStream, Specs, !ModuleInfo, !IO) :-
|
||||
% XXX We should add a mechanism that would allow us to check whether
|
||||
% we have already read in this file, and if we have, then avoid reading
|
||||
% it in again.
|
||||
@@ -173,28 +173,34 @@ tuple_arguments(ProgressStream, !ModuleInfo, !IO) :-
|
||||
globals.get_opt_tuple(Globals, OptTuple),
|
||||
TraceCountsFile = OptTuple ^ ot_tuple_trace_counts_file,
|
||||
( if TraceCountsFile = "" then
|
||||
report_warning(ProgressStream, Globals,
|
||||
"Warning: --tuple requires --tuple-trace-counts-file to work.\n",
|
||||
!IO)
|
||||
Pieces = [words("Warning: --tuple requires"),
|
||||
words("--tuple-trace-counts-file to work."), nl],
|
||||
Severity = severity_warning(warn_requested_by_option),
|
||||
Spec = no_ctxt_spec($pred, Severity, phase_options, Pieces),
|
||||
Specs = [Spec]
|
||||
else
|
||||
read_trace_counts_file(TraceCountsFile, Result, !IO),
|
||||
(
|
||||
Result = rtcf_ok(_, TraceCounts),
|
||||
tuple_arguments_with_trace_counts(ProgressStream,
|
||||
!ModuleInfo, TraceCounts)
|
||||
TraceCounts, !ModuleInfo),
|
||||
Specs = []
|
||||
;
|
||||
Result = rtcf_error_message(Reason),
|
||||
string.format(
|
||||
"Warning: unable to read trace count summary from %s (%s)\n",
|
||||
[s(TraceCountsFile), s(Reason)], Message),
|
||||
report_warning(ProgressStream, Globals, Message, !IO)
|
||||
ReasonInParens = "(" ++ Reason ++ ")",
|
||||
Pieces = [words("Warning: unable to read trace count summary"),
|
||||
words("from"), fixed(TraceCountsFile),
|
||||
words(ReasonInParens), nl],
|
||||
Severity = severity_warning(warn_requested_by_option),
|
||||
Spec = no_ctxt_spec($pred, Severity, phase_read_files, Pieces),
|
||||
Specs = [Spec]
|
||||
)
|
||||
).
|
||||
|
||||
:- pred tuple_arguments_with_trace_counts(io.text_output_stream::in,
|
||||
module_info::in, module_info::out, trace_counts::in) is det.
|
||||
trace_counts::in, module_info::in, module_info::out) is det.
|
||||
|
||||
tuple_arguments_with_trace_counts(ProgressStream, !ModuleInfo, TraceCounts0) :-
|
||||
tuple_arguments_with_trace_counts(ProgressStream, TraceCounts0, !ModuleInfo) :-
|
||||
module_info_get_globals(!.ModuleInfo, Globals),
|
||||
% We use the same cost options as for the stack optimisation.
|
||||
globals.get_opt_tuple(Globals, OptTuple),
|
||||
@@ -229,9 +235,9 @@ tuple_arguments_with_trace_counts(ProgressStream, !ModuleInfo, TraceCounts0) :-
|
||||
SCCs, !ModuleInfo, counter.init(0), _, map.init, TransformMap),
|
||||
|
||||
% Update the callers of the original procedures to call their
|
||||
% transformed versions instead. Do the same for the transformed
|
||||
% procedures themselves.
|
||||
% transformed versions instead.
|
||||
list.foldl(fix_calls_in_procs(TransformMap), SCCs, !ModuleInfo),
|
||||
% Do the same for the transformed procedures themselves.
|
||||
fix_calls_in_transformed_procs(TransformMap, !ModuleInfo).
|
||||
|
||||
%-----------------------------------------------------------------------------%
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
% vim: ft=mercury ts=4 sw=4 et
|
||||
%---------------------------------------------------------------------------%
|
||||
% Copyright (C) 1997-2012 The University of Melbourne.
|
||||
% Copyright (C) 2022-2025 The Mercury team.
|
||||
% Copyright (C) 2022-2026 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.
|
||||
%---------------------------------------------------------------------------%
|
||||
@@ -220,7 +220,6 @@
|
||||
:- implementation.
|
||||
|
||||
:- import_module libs.color_schemes.
|
||||
:- import_module libs.compiler_util.
|
||||
:- import_module mdbcomp.
|
||||
:- import_module mdbcomp.prim_data.
|
||||
:- import_module mdbcomp.sym_name.
|
||||
@@ -357,7 +356,14 @@ do_write_error_spec(Stream, OptionTable, LimitErrorContextsMap, ColorDb,
|
||||
io.set_exit_status(1, !IO)
|
||||
;
|
||||
ActualSeverity = actual_severity_warning,
|
||||
record_warning_opt_table(OptionTable, !IO)
|
||||
getopt.lookup_bool_option(OptionTable, halt_at_warn,
|
||||
HaltAtWarn),
|
||||
(
|
||||
HaltAtWarn = yes,
|
||||
io.set_exit_status(1, !IO)
|
||||
;
|
||||
HaltAtWarn = no
|
||||
)
|
||||
;
|
||||
ActualSeverity = actual_severity_informational
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user