From dbd19430ef623eb4e66fc908c1f5378bc013ab24 Mon Sep 17 00:00:00 2001 From: Zoltan Somogyi Date: Thu, 4 Jun 2020 13:58:00 +1000 Subject: [PATCH] Use full error_specs instead of pieces. compiler/compile_target_code.m: compiler/fact_table.m: compiler/mercury_compile_mlds_back_end.m: compiler/module_cmds.m: compiler/pred_table.m: Replace calls to write_error_pieces* with code that constructs full error_specs and then writes them out. compiler/error_util.m: Add a new phase, phase_fact_table_check, for the new code in fact_table.m. --- compiler/compile_target_code.m | 6 ++- compiler/error_util.m | 2 + compiler/fact_table.m | 64 ++++++++++++------------ compiler/mercury_compile_mlds_back_end.m | 16 +++--- compiler/module_cmds.m | 6 ++- compiler/pred_table.m | 4 +- 6 files changed, 56 insertions(+), 42 deletions(-) diff --git a/compiler/compile_target_code.m b/compiler/compile_target_code.m index 59a7439ee..bd7d8c626 100644 --- a/compiler/compile_target_code.m +++ b/compiler/compile_target_code.m @@ -2759,8 +2759,10 @@ process_link_library(Globals, MercuryLibDirs, LibName, LinkerOpt, !Succeeded, ; MaybeDirName = error(Error), LinkerOpt = "", - write_error_pieces_maybe_with_context(Globals, no, 0, - [words(Error)], !IO), + Spec = error_spec($pred, severity_error, phase_read_files, + [error_msg(no, treat_as_first, 0, + [always([words(Error), suffix(".\n")])])]), + write_error_spec_ignore(Globals, Spec, !IO), !:Succeeded = no ) else diff --git a/compiler/error_util.m b/compiler/error_util.m index afd72a047..707189463 100644 --- a/compiler/error_util.m +++ b/compiler/error_util.m @@ -188,6 +188,7 @@ ; phase_mode_check(mode_report_control) ; phase_purity_check ; phase_detism_check + ; phase_fact_table_check ; phase_oisu_check ; phase_simplify(mode_report_control) ; phase_style @@ -1197,6 +1198,7 @@ get_maybe_mode_report_control(phase_polymorphism) = no. get_maybe_mode_report_control(phase_mode_check(Control)) = yes(Control). get_maybe_mode_report_control(phase_purity_check) = no. get_maybe_mode_report_control(phase_detism_check) = no. +get_maybe_mode_report_control(phase_fact_table_check) = no. get_maybe_mode_report_control(phase_oisu_check) = no. get_maybe_mode_report_control(phase_simplify(Control)) = yes(Control). get_maybe_mode_report_control(phase_style) = no. diff --git a/compiler/fact_table.m b/compiler/fact_table.m index 1c31fc1e2..371b082dc 100644 --- a/compiler/fact_table.m +++ b/compiler/fact_table.m @@ -1211,12 +1211,13 @@ infer_determinism_pass_2([ProcID - FileName | ProcFiles], Globals, ) else io.progname_base("mercury_compile", ProgName, !IO), - string.format( - "%s: an error occurred in the `sort' program " - ++ "during fact table determinism inference.", - [s(ProgName)], Msg), - write_error_pieces_plain(Globals, [words(Msg)], !IO), - io.set_exit_status(1, !IO), + Pieces = + [fixed(ProgName), suffix(":"), words("an error occurred"), + words("in the"), quote("sort"), words("program"), + words("during fact table determinism inference."), nl], + Spec = error_spec($pred, severity_error, phase_fact_table_check, + [error_msg(no, treat_as_first, 0, [always(Pieces)])]), + write_error_spec_ignore(Globals, Spec, !IO), Determinism = detism_erroneous ) ; @@ -1399,10 +1400,11 @@ maybe_append_data_table(Globals, yes, OutputFileName, DataFileName, !IO) :- ( if ExitStatus = 0 then true else - Msg = "An error occurred while concatenating " ++ - "fact table output files.", - write_error_pieces_plain(Globals, [words(Msg)], !IO), - io.set_exit_status(1, !IO) + Pieces = [words("An error occurred while concatenating"), + words("fact table output files."), nl], + Spec = error_spec($pred, severity_error, phase_fact_table_check, + [error_msg(no, treat_as_first, 0, [always(Pieces)])]), + write_error_spec_ignore(Globals, Spec, !IO) ) ; Result = error(ErrorCode), @@ -1565,11 +1567,13 @@ read_sort_file_line(FactArgInfos, ArgModes, ModuleInfo, MaybeSortFileLine, Result = error(ErrorCode), io.error_message(ErrorCode, ErrorMessage), io.input_stream_name(FileName, !IO), - string.format("Error reading file `%s':", [s(FileName)], Msg), + Pieces = + [words("Error reading file"), quote(FileName), suffix(":"), nl, + words(ErrorMessage), nl], + Spec = error_spec($pred, severity_error, phase_fact_table_check, + [error_msg(no, treat_as_first, 0, [always(Pieces)])]), module_info_get_globals(ModuleInfo, Globals), - write_error_pieces_plain(Globals, - [words(Msg), nl, words(ErrorMessage)], !IO), - io.set_exit_status(1, !IO), + write_error_spec_ignore(Globals, Spec, !IO), MaybeSortFileLine = no ). @@ -3371,11 +3375,12 @@ delete_temporary_file(Globals, FileName, !IO) :- Result = error(ErrorCode), io.error_message(ErrorCode, ErrorMsg), io.progname_base("mercury_compile", ProgName, !IO), - string.format("%s: error deleting file `%s:", - [s(ProgName), s(FileName)], Msg), - Pieces = [words(Msg), nl, words(ErrorMsg), nl], - write_error_pieces_plain(Globals, Pieces, !IO), - io.set_exit_status(1, !IO) + Pieces = [fixed(ProgName), suffix(":"), words("error deleting file"), + quote(FileName), suffix(":"), nl, + words(ErrorMsg), suffix("."), nl], + Spec = error_spec($pred, severity_error, phase_fact_table_check, + [error_msg(no, treat_as_first, 0, [always(Pieces)])]), + write_error_spec_ignore(Globals, Spec, !IO) ). :- pred write_call_system_error_msg(globals::in, string::in, io.error::in, @@ -3384,10 +3389,12 @@ delete_temporary_file(Globals, FileName, !IO) :- write_call_system_error_msg(Globals, Cmd, ErrorCode, !IO) :- io.error_message(ErrorCode, ErrorMsg), io.progname_base("mercury_compile", ProgName, !IO), - string.format("%s: error executing system command `%s:", - [s(ProgName), s(Cmd)], Msg), - write_error_pieces_plain(Globals, [words(Msg), nl, words(ErrorMsg)], !IO), - io.set_exit_status(1, !IO). + Pieces = [fixed(ProgName), suffix(":"), + words("error executing system command"), quote(Cmd), suffix(":"), nl, + words(ErrorMsg), suffix("."), nl], + Spec = error_spec($pred, severity_error, phase_fact_table_check, + [error_msg(no, treat_as_first, 0, [always(Pieces)])]), + write_error_spec_ignore(Globals, Spec, !IO). %-----------------------------------------------------------------------------% @@ -3421,14 +3428,9 @@ print_error_reports(Globals, RevErrors, !IO) :- is det. print_error_report(Globals, MaybeContext - Pieces, !IO) :- - ( - MaybeContext = yes(Context), - write_error_pieces(Globals, Context, 0, Pieces, !IO) - ; - MaybeContext = no, - write_error_pieces_plain(Globals, Pieces, !IO) - ), - io.set_exit_status(1, !IO). + Spec = error_spec($pred, severity_error, phase_fact_table_check, + [error_msg(MaybeContext, treat_as_first, 0, [always(Pieces)])]), + write_error_spec_ignore(Globals, Spec, !IO). :- pred print_file_open_error(globals::in, maybe(context)::in, string::in, string::in, io.error::in, io::di, io::uo) is det. diff --git a/compiler/mercury_compile_mlds_back_end.m b/compiler/mercury_compile_mlds_back_end.m index 54f8912c6..ec50f1502 100644 --- a/compiler/mercury_compile_mlds_back_end.m +++ b/compiler/mercury_compile_mlds_back_end.m @@ -75,6 +75,7 @@ :- import_module top_level.mercury_compile_llds_back_end. :- import_module getopt_io. +:- import_module maybe. :- import_module pprint. :- import_module require. :- import_module string. @@ -306,12 +307,15 @@ maybe_add_heap_ops(Verbose, Stats, !HLDS, !IO) :- maybe_write_string(Verbose, "% done.\n", !IO), maybe_report_stats(Stats, !IO) else - Msg = "Sorry, not implemented: `--high-level-code' and just one of " ++ - "`--reclaim-heap-on-semidet-failure' and " ++ - "`--reclaim-heap-on-nondet-failure'. " ++ - "Use `--(no-)reclaim-heap-on-failure' instead.", - write_error_pieces_plain(Globals, [words(Msg)], !IO), - io.set_exit_status(1, !IO) + Pieces = [words("Sorry, not implemented:"), + quote("--high-level-code"), words("and just one of"), + quote("--reclaim-heap-on-semidet-failure"), words("and"), + quote("--reclaim-heap-on-nondet-failure"), suffix("."), + words("Use"), quote("--(no-)reclaim-heap-on-failure"), + words("instead."), nl], + Spec = error_spec($pred, severity_error, phase_read_files, + [error_msg(no, treat_as_first, 0, [always(Pieces)])]), + write_error_spec_ignore(Globals, Spec, !IO) ). :- pred maybe_mark_tail_rec_calls_hlds(bool::in, bool::in, diff --git a/compiler/module_cmds.m b/compiler/module_cmds.m index 20969af41..5ee1a4ce2 100644 --- a/compiler/module_cmds.m +++ b/compiler/module_cmds.m @@ -1208,8 +1208,10 @@ find_erlang_library_path(Globals, MercuryLibDirs, LibName, LibPath, !IO) :- ; MaybeDirName = error(Error), LibPath = "", - write_error_pieces_maybe_with_context(Globals, no, 0, [words(Error)], - !IO) + Spec = error_spec($pred, severity_error, phase_read_files, + [error_msg(no, treat_as_first, 0, + [always([words(Error), suffix(".\n")])])]), + write_error_spec_ignore(Globals, Spec, !IO) ). :- func pa_option(bool, bool, dir_name) = string. diff --git a/compiler/pred_table.m b/compiler/pred_table.m index 6714e7cb9..f681e3acb 100644 --- a/compiler/pred_table.m +++ b/compiler/pred_table.m @@ -1063,7 +1063,9 @@ find_matching_pred_id(ModuleInfo, [PredId | PredIds], TVarSet, ExistQTVars, qual_pf_sym_name_orig_arity(OtherPredCallId), suffix("."), words("You need to use an explicit module qualifier."), nl], - write_error_pieces(Globals, Context, 0, Pieces, !IO) + Spec = simplest_spec($pred, severity_error, phase_type_check, + Context, Pieces), + write_error_spec_ignore(Globals, Spec, !IO) ), unexpected($pred, "unresolvable predicate overloading") else