Convert the make_hlds stage of the compiler from printing out error messages

Estimated hours taken: 14
Branches: main

Convert the make_hlds stage of the compiler from printing out error messages
one at a time to gathering them all up and printing them all at once after
sorting and deleting duplicates. This approach makes it much easier to be
consistent about updating the exit status in the I/O state and the error count
in the module info, and indeed this diff fixes some bugs in this area.

This approach also means that instead of threading a pair of I/O states
through these modules, we now mostly thread through a list of error
specifications. In a couple of places, we create the I/O states we need
for printing progress messages using trace goals.

configure.in:
	Check that the installed compiler supports trace goals (perhaps with
	warnings), since the compiler now uses them.

compiler/Mercury.options:
	Temporarily compensate for a bug in the handling of trace goals.

compiler/add_class.m:
compiler/add_clause.m:
compiler/add_mode.m:
compiler/add_pragma.m:
compiler/add_pred.m:
compiler/add_solver.m:
compiler/add_type.m:
compiler/field_access.m:
compiler/foreign.m:
compiler/make_hlds_error.m:
compiler/make_hlds_passes.m:
compiler/make_hlds_warn.m:
compiler/module_qual.m:
compiler/modules.m:
compiler/qual_info.m:
compiler/state_var.m:
compiler/superhomogeneous.m:
	Make the change described at the top. In many cases, this required
	changing code to error util instead of io.write_strings to create the
	error messages.

	In some cases, move a predicate used in one module but defined in
	another module to the first module.

	Delete some predicates whose job used to be to test options to see
	whether a message should be generated, since we can now embed the
	option value that a message depends on in the error message itself.

	In module_qual.m, remove unnecessary module qualifications.

	In modules.m, give explicit names to a bunch of lambda expressions.

	Reformat comments to exploit the available columns.

compiler/check_typeclass.m:
	Conform to the changes above. Mark with XXX the places where we are
	ignoring the proper update of the error count in module_infos.

compiler/modes.m:
compiler/post_typecheck.m:
compiler/stratify.m:
compiler/table_gen.m:
compiler/unused_args.m:
	Use error_specs instead of plain pieces to print error messages.

compiler/options.m:
	Rename an option that conflicts with a language keyword.

compiler/handle_options.m:
	Conform to the change to options.m.

compiler/prog_data.m:
	Rename some function symbols that conflict with language keywords.

compiler/prog_out.m:
compiler/prog_io_util.m:
	Conform the change above, and delete some predicates that have
	now become unused.

compiler/mercury_compile.m:
	Rename a predicate to avoid an ambiguity.

	Conform to the changes above.

compiler/hlds_out.m:
compiler/make.module_dep_file.m:
compiler/make_hlds.m:
compiler/mercury_to_mercury.m:
compiler/mode_errors.m:
compiler/prog_io.m:
	Conform to the changes above. In some cases, delete predicates
	that aren't needed anymore.

tests/invalid/errors.err_exp:
tests/invalid/errors1.err_exp:
tests/invalid/state_vars_test3.err_exp:
tests/invalid/undef_inst.err_exp:
	Update this expected output to reflect the fact that we now sort
	the error messages.

tests/invalid/missing_interface_import2.err_exp:
tests/warnings/double_underscore.exp:
	Update this expected output to reflect the fact that we no longer
	print the same error message twice.

tests/invalid/missing_det_decls.err_exp:
	Update this expected output to reflect the fact that we now indent
	an error messages correctly.

tests/invalid/multimode_syntax.err_exp:
	Update this expected output to reflect the fact that we now use
	error_util instead of plain io.writes to create an error message.

tests/invalid/typeclass_test.err_exp:
tests/invalid/unsatisfiable_constraint.err_exp:
	Update this expected output to reflect minor improvements in the
	formatting of an error message.
This commit is contained in:
Zoltan Somogyi
2006-09-10 23:39:17 +00:00
parent 2648efda42
commit f070e2a1b7
47 changed files with 3348 additions and 3396 deletions

View File

@@ -32,13 +32,11 @@
:- import_module parse_tree.prog_item.
:- import_module assoc_list.
:- import_module io.
:- import_module list.
:- import_module map.
:- import_module maybe.
:- import_module pair.
:- import_module term.
:- import_module varset.
%-----------------------------------------------------------------------------%
@@ -68,9 +66,6 @@
:- func get_any_errors4(maybe4(T1, T2, T3, T4, U))
= assoc_list(string, term(U)).
:- pred report_string_term_error(term.context::in, varset(U)::in,
pair(string, term(U))::in, io::di, io::uo) is det.
:- type maybe_functor == maybe_functor(generic).
:- type maybe_functor(T) == maybe2(sym_name, list(term(T))).
@@ -218,13 +213,6 @@ get_any_errors3(error3(Errors)) = Errors.
get_any_errors4(ok4(_, _, _, _)) = [].
get_any_errors4(error4(Errors)) = Errors.
report_string_term_error(Context, VarSet, Msg - ErrorTerm, !IO) :-
TermStr = mercury_term_to_string(ErrorTerm, VarSet, no),
Pieces = [words("Error:"), words(Msg), suffix(":"),
fixed("`" ++ TermStr ++ "'.")],
write_error_pieces(Context, 0, Pieces, !IO),
io.set_exit_status(1, !IO).
add_context(error1(Errs), _, error2(Errs)).
add_context(ok1(Item), Context, ok2(Item, Context)).