[m-rev.] for post-commit review: using error_util in parse_tree

Julien Fischer juliensf at csse.unimelb.edu.au
Wed Jul 16 14:49:15 AEST 2008


On Wed, 16 Jul 2008, Zoltan Somogyi wrote:

> Switch to using error_util to generate error message during the process of
> converting terms to prog_items.
>
> In many predicates, we used to return error messages as a string/term pair,
> with the string being the error message and a term, which both provided
> the context and was printed after the message. We now return error indications
> as lists of error_specs. These include a printout of the relevant term only
> if this helps users understand the nature or the location of the error.
> To make the printouts easier to understand we print variable names in them
> using the applicable varsets. (The old version of the compiler used to print
> each error term long after it lost track of the right varset, and thus used
> a dummy varset that yielded error messages referring to _1, _2 etc instead
> of the variable names used by the programmer.)
>
> Sometimes the callers of some parse predicates prepended other strings
> indicating the context of the error in front of the error string.
> This diff changes things so that now the caller instead passes a list
> of format components describing the context to the predicates that construct
> the error_specs.
>
> In some places, simplify the code, e.g. by factoring out common code, and by
> inlining some auxiliary predicates (we used to need these auxiliary predicates
> for indexing when we executed the compiler using Prolog, but those days are
> long past).
>
> Mark with XXXs places where I think the error messages or their contexts
> could be improved, and places where the structure of the code could be
> improved.
>
> compiler/prog_io_util.m:
> 	Change the representation of the maybeN types to use error_spec lists.
>
> compiler/prog_io.m:
> compiler/prog_io_dcg.m:
> compiler/prog_io_goal.m:
> compiler/prog_io_pragma.m:
> compiler/prog_io_typeclass.m:
> compiler/prog_io_util.m:
> 	Change the way we generate error messages along the lines described
> 	at the top.
>
> 	In several cases, this required adding extra arguments (varsets,
> 	context descriptions) to predicates for use in error messages.
>
> 	Some of these predicates were also used in contexts where the caller
> 	was interested only in success, and would ignore any error messages.
> 	In these cases, add a version of the predicate that does not require
> 	the extra arguments, and which is semidet (to allow the caller to
> 	avoid a test for ok).
>
> compiler/error_util.m:
> 	Add a mechanism for changing the case of the next format_component,
> 	to allow an error message to be appended to a list of format_components
> 	providing the context that generates good-looking output whether or not
> 	that context is empty.
>
> 	Replace some bools with purpose-specific types.
>
> 	Make sort_error_specs internal to the module, since outside modules
> 	should never need to use it.
>
> 	Use cords instead of reversed lists to simplify some parts of the
> 	internal implementation.
>
> compiler/mercury_to_mercury.m:
> 	Provide a mechanism to print out terms only if they aren't too big,
> 	for use in our error messages.
>
> compiler/prog_item.m:
> 	Delete the message_list type, and note a future improvement.
>
> compiler/prog_out.m:
> 	Delete the predicates for printing message_lists.
>
> compiler/intermod.m:
> compiler/modules.m:
> 	Change the way we print out error messages along the lines described
> 	at the top.
>
> compiler/add_clause.m:
> compiler/field_access.m:
> compiler/recompilation.check.m:
> compiler/recompilation.version.m:
> compiler/superhomogeneous.m:
> 	Conform to the changes above by modifying how we generate error
> 	messages.
>
> compiler/add_class.m:
> compiler/add_pragma.m:
> compiler/check_typeclass.m:
> compiler/common.m:
> compiler/make.module_dep_file.m:
> compiler/make_hlds_error.m:
> compiler/make_hlds_passes.m:
> compiler/mercury_compile.m:
> compiler/mode_errors.m:
> compiler/modes.m:
> compiler/options_file.m:
> compiler/prog_ctgc.m:
> compiler/prog_event.m:
> compiler/purity.m:
> compiler/trans_opt.m:
> compiler/typecheck.m:
> 	Trivial updates to conform to the changes above.
>
> compiler/prog_data.m:
> 	Add some field names and access functions for use in the modules above.
>
> library/list.m:
> 	Add list.contains, which is list.member with the arguments reversed
> 	to make it possibly to partially apply it.

That addition should be mentioned in the NEWS file.

> tests/invalid/bad_finalise_decl.err_exp:
> tests/invalid/bad_initialise_decl.err_exp:
> tests/invalid/bad_mutable.err_exp:
> tests/invalid/bigtest.err_exp:
> tests/invalid/conflicting_fs.err_exp:
> tests/invalid/constrained_poly_insts.err_exp:
> tests/invalid/errors.err_exp:
> tests/invalid/func_errors.err_exp:
> tests/invalid/fundeps_unbound_in_ctor.err_exp:
> tests/invalid/fundeps_vars.err_exp:
> tests/invalid/impl_def_literal_syntax.err_exp:
> tests/invalid/inst_list_dup.err_exp:
> tests/invalid/invalid_typeclass.err_exp:
> tests/invalid/kind.err_exp:
> tests/invalid/null_char.err_exp:
> tests/invalid/pragma_source_file.err_exp:
> tests/invalid/predmode.err_exp:
> tests/invalid/reserve_tag.err_exp:
> tests/invalid/some.err_exp:
> tests/invalid/specified.err_exp:
> tests/invalid/trace_goal_env.err_exp:
> tests/invalid/type_vars.err_exp:
> tests/invalid/typeclass_test_1.err_exp:
> tests/invalid/typeclass_test_11.err_exp:
> tests/invalid/typeclass_test_2.err_exp:
> tests/invalid/unbound_type_vars.err_exp:
> tests/invalid/unicode1.err_exp:
> tests/invalid/unicode2.err_exp:
> tests/invalid/uu_type.err_exp:
> tests/invalid/vars_in_wrong_places.err_exp:
> tests/invalid/with_type.err_exp:
> tests/invalid/purity/purity_nonsense2.err_exp:
> 	Update the expected error messages.

I've had a quick read through the diff and it seems okay.

Julien.
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list