Commit Graph

9 Commits

Author SHA1 Message Date
Zoltan Somogyi
9ab132ac57 Simplify error messages about unimported ancestors.
compiler/typecheck_errors.m:
    Replace the indirect computation of a set using nondet code
    inside a call to solutions/2 with direct code using set operations.

    Move code that constructs the end of an error message sentence
    to the code that constructs its beginning. This can replace
    a single sentence with a subsidiary clause in parentheses
    with two simpler sentences, which is easier to read anyway.

tests/invalid/transitive_import_class.err_exp:
tests/invalid/undef_symbol.err_exp:
tests/invalid_submodules/missing_parent_import.err_exp:
    Expect the updated form of the affected error messages.
2021-08-17 23:21:12 +10:00
Zoltan Somogyi
fdd141bf77 Clean up the tests in the other test directories.
tests/invalid/*.{m,err_exp}:
tests/misc_tests/*.m:
tests/mmc_make/*.m:
tests/par_conj/*.m:
tests/purity/*.m:
tests/stm/*.m:
tests/string_format/*.m:
tests/structure_reuse/*.m:
tests/submodules/*.m:
tests/tabling/*.m:
tests/term/*.m:
tests/trailing/*.m:
tests/typeclasses/*.m:
tests/valid/*.m:
tests/warnings/*.{m,exp}:
    Make these tests use four-space indentation, and ensure that
    each module is imported on its own line. (I intend to use the latter
    to figure out which subdirectories' tests can be executed in parallel.)

    These changes usually move code to different lines. For the tests
    that check compiler error messages, expect the new line numbers.

browser/cterm.m:
browser/tree234_cc.m:
    Import only one module per line.

tests/hard_coded/boyer.m:
    Fix something I missed.
2015-02-16 12:32:18 +11:00
Zoltan Somogyi
5a639e1656 Quote cons_ids consistently in error messages.
compiler/error_util.m:
    Add a format piece for identifying cons_ids.

compiler/hlds_out_util.m:
compiler/prog_out.m:
    Add a version of the predicate that convert cons_ids to string
    that quotes appropriately for error messages.

    Move this predicate, and some existing predicates for converting
    cons_ids to strings from hlds_out_util.m to prog_out.m, so that
    error_util.m, which is part of the parse_tree.m package, can use them.
    Since cons_ids are defined in prog_data, a part of parse_tree, they
    should always have been here.

    Make the same move for some other predicates that also convert to strings
    values of other types defined in prog_data.m.

compiler/prog_mode.m:
compiler/prog_util.m:
    Move a predicate dealing with cons_ids from prog_mode.m to prog_out.m,
    since prog_out needs it now.

compiler/det_report.m:
compiler/post_typecheck.m:
    Use the new format piece where relevant.

compiler/typecheck_errors.m:
    Use the new format piece where relevant.

    Avoid prevarication about singular vs plural when not necessary.

tests/compiler/*.m:
    Conform to the above.

tests/invalid/*.err_exp:
    Update these to expect the new error messages.
2015-01-31 20:39:19 +11:00
Zoltan Somogyi
91ce3a67a2 Avoid a compiler abort when people put a period in the middle of a clause.
The abort was caused by the fact that when the parser found an item that
looks like a fact for an undeclared predicate, such as the predicate ','/,
it created a hlds_pred filled with a clause_info in which terms that the
user intended to be goals are instead taken to be terms. Any reference
to predicates in those terms are taken by purity-checking to be higher order
references, which need a mode declaration. If the reference is to a predicate
(such as ,/2) whose declaration is implicit, that mode declaration will be
missing.

The fix has two parts. First, do not generate an abort in purity checking
when finding the mode declaration of a predicate or function in (what seems to
be) a higher order term is missing. Second, do not generate implicit
declarations for ,/2, since this is NEVER what the user wants.

A third part of this diff is an improvement in the contexts we record
for terms, for better error messages. I noticed the need for this when
looking at the compiler's output for the new cases.

compiler/post_typecheck.m:
   When finding an apparent reference to a predicate or function with
   no mode declarations, do not abort; instead, report an error.

compiler/purity.m:
   Record the error reported by post_typecheck.m.

compiler/add_clause.m:
   If we see a clause for `,'/2, do NOT treat it as implicitly defining
   a ,/2 predicate. Instead, generate a situation-specific error message that
   mentions the usual cause of the error.

compiler/add_pred.m:
   Clean up the predicates that add the implicit predicate declarations
   by making them both update module_infos, and by putting their arguments
   into a consistent order.

compiler/make_hlds_passes.m:
   Do likewise for a couple of predicates here.

compiler/add_pragma.m:
   Conform to the change to add_pred.m.

compiler/superhomogeneous.m:
   When expanding a term such as

      line 1: p(a,
      line 2: p(b,
      line 3: c))

   associate line 2 with the unification of a fresh variable with b,
   and line 3 with the unification of a fresh variable with c. We used
   to use the context of the top level term, which in this case is line 1,
   instead.

   This makes the compiler generate better (less misleading) output for the
   ref_to_implicit_pred.m test case below, as well as in many other cases.

compiler/state_var.m:
   When replacing !.X or !:X with a fresh variable term, copy the context
   of the original functor term to the new variable term. Before the change
   to superhomogeneous.m, this wasn't needed since the context of that term
   was ignored, but now we use it.

tests/invalid/ref_to_implicit_pred.{m,err_exp}:
   New test case to test the first part of the fix.

tests/invalid/ref_to_implicit_comma.{m,err_exp}:
   New test case to test the second part of the fix.

tests/invalid/Mmakefile:
   Enable both new test cases.

tests/hard_coded/impl_def_literal.{m,exp}:
   Update this expected output for the more accurate contexts we now
   generate, and update the comment in the source code accordingly.

tests/invalid/ambiguous_overloading_error.exp:
tests/invalid/max_error_line_width.err_exp:
tests/invalid/transitive_import_class.err_exp:
tests/warnings/ambiguous_overloading.exp:
   Update these expected outputs for the more accurate contexts we now
   generate.
2014-04-17 23:14:49 +10:00
Zoltan Somogyi
5eee81204e A big step towards cleaning up the way we handle errors.
Estimated hours taken: 28
Branches: main

A big step towards cleaning up the way we handle errors. The main changes are

- the provision, in error_util.m, of a mechanism for completely specifying
  everything to do with a single error in one data structure,

- the conversion of typecheck_errors.m from using io.write_string to
  using this new capability,

- the conversion of mode_errors.m and det_report.m from using
  write_error_pieces to using this new capability, and

- consistently using the quoting style `symname'/N instead of `symname/N'
  in error_util and hlds_error_util (previously, error_util used the former
  but hlds_error_util used the latter).

This diff sets up later diffs which will collect all error specifications
in a central place and print them all at once, in order.

compiler/error_util.m:
	The new type error_spec, which completely specifies an error.
	An error_spec may have multiple components with different contexts
	and may have parts which are printed only under certain conditions,
	e.g. a given option being set. Each error_spec has a severity
	and also records which phase found the error.

	The new predicate write_error_spec takes care of updates of the exit
	status for errors and (if --halt-at-warn is set) for warnings. It also
	takes care of setting the flag that calls for the reminder about -E
	at the end.

	This diff also makes it simpler to use the ability to print arbitrary
	output. It adds the ability to include integers in messages directly,
	and the ability to create blank lines. It renames some function symbols
	to avoid ambiguities.

	Move a predicate that only used by typecheck_errors.m to that file.

compiler/hlds_error_util.m:
	Switch to the `symname'/N quoting style for describing predicates and
	procedures.

compiler/prog_util.m:
	Switch to the `symname'/N quoting style for describing
	sym_name_and_arity.

compiler/hlds_module.m:
	Provide a predicate to increment the number of errors not by one,
	but by the number of errors printed by write_error_spec.

	Fix some documentation rot.

compiler/typecheck_errors.m:
	Use write_error_spec instead of io.write_strings to print error
	messages. In several cases, improve the formatting of the messages
	printed.

	Mark a number of places where we don't (yet) update the number of
	errors in the module_info correctly.

	Rename the checkpoint predicate to avoid potential ambiguity with
	similar predicates in e.g. mode_info.

compiler/typecheck_info.m:
	Group the code for writing stuff out together in one bunch. For each
	such predicate, create another that returns a list of format components
	instead of doing I/O directly.

compiler/typecheck.m:
	Move the code for writing inference messages here from
	typecheck_errors.m, since these messages aren't errors.

compiler/mode_errors.m:
compiler/det_report.m:
	Use write_error_spec instead of write_error_pieces. In the case of
	mode_errors.m, this means we now get correct the set of circumstances
	in which we set the flag that calls for the reminder about -E.

compiler/add_pragma.m:
compiler/add_type.m:
	Convert some code that used to use write_error_pieces to print error
	messages to use write_error_spec instead.

compiler/assertion.m:
compiler/hlds_pred.m:
compiler/post_typecheck.m:
	Assertion.m used to contain some code to check for assertions in the
	interface that mention predicates that are not exported. Move most
	of this code to post_typecheck.m (which is where this code used to be
	called from). One small part, which is a test for a particular property
	of import_statuses, is moved to hlds_pred.m to be with all the other
	similar tests of import_statuses.

compiler/prog_util.m:
	Change unqualify_name from a predicate to a function.

compiler/pred_table.m:
compiler/hlds_out.m:
	Avoid some ambiguities by adding a suffix to the names of some
	predicates.

compiler/*.m:
	Conform to the changes above.

library/list.m:
	Add a function that was previously present (with different names)
	in two compiler modules.

tests/hard_coded/allow_stubs.exp:
	Update the format of the expected exception.

tests/invalid/errors2.err_exp2:
	Remove this file. As far as I can tell, it was never the correct
	expected output on the main branch. (It originated on the alias branch
	way back in the mists of time.)

tests/invalid/*.err_exp:
tests/invalid/purity/*.err_exp:
tests/warnings/*.exp:
	Update the format of the expected error messages.

tests/recompilation/*.err_exp.2:
	Update the format of the expected messages about what was modified.
2006-09-07 05:51:48 +00:00
Julien Fischer
e069d16ab1 Do not display the For more information try recompiling with -E'' prompt
Estimated hours taken: 1.5
Branches: main

Do not display the `For more information try recompiling with `-E'' prompt
unless we really mean it, i.e. there is actually more information available.

XXX This change is incomplete for the mode_errors module because that
module requires more substantial changes to make this work - I'll do
that as a separate diff.

compiler/globals.m
	Add a new global (and access predicates) that keeps track of whether
	we have any verbose error information that could be displayed if we
	recompiled with `-E'.

compiler/mercury_compile.m
	Check the new global flag before prompting the user to recompile with
	`-E'.

compiler/mode_errors.m
	Add an XXX comment about needing to respect the extra error info flag
	properly.

compiler/accumulator.m
compiler/add_clause.m
compiler/add_pred.m
compiler/add_type.m
compiler/assertion.m
compiler/check_typeclass.m
compiler/det_report.m
compiler/magic_util.m
compiler/make_hlds_error.m
compiler/modes.m
compiler/module_qual.m
compiler/modules.m
compiler/post_typecheck.m
compiler/purity.m
compiler/stratify.m
compiler/typecheck_errors.m
	Set the new global flag when we come across an error
	for which we have a verbose error message.

tests/recompilation/*:
tests/invalid/*:
	Update expected error files.
2005-09-14 05:27:11 +00:00
Ralph Becket
a8ffd3680c Change the compiler and tools so that .' and not :' is now used as the
Estimated hours taken: 14
Branches: main

Change the compiler and tools so that `.' and not `:' is now used as the
module separator in all output.

Infix `.' now has associativity yfx and priority 10.

NEWS:
	Report the change.

configure.in:
	Amend the test for an up-to-date Mercury compiler to check whether
	it recognises `.' as a module qualifier.

compiler/code_gen.m:
compiler/error_util.m:
compiler/hlds_out.m:
compiler/prog_out.m:
compiler/prog_util.m:
compiler/rl_exprn.m:
compiler/rl_gen.m:
compiler/source_file_map.m:
compiler/unused_args.m:
library/io.m:
library/rtti_implementation.m:
library/type_desc.m:
runtime/mercury_debug.c:
runtime/mercury_deconstruct.c:
runtime/mercury_stack_trace.c:
	Change `:' to `.' as module separator for output.

compiler/mercury_to_mercury.m:
compiler/prog_io_typeclass.m:
	As above.
	Fixed a bug where `.' was not being recognised as a module separator.

doc/reference_manual.texi:
	Report the change.

library/term_io.m:
	Ensure that infix `.' is written without surrounding spaces.

tests/hard_coded/dot_separator.m:
tests/hard_coded/dot_separator.exp:
tests/hard_coded/Mmakefile:
	Test case added.
2003-01-17 05:57:20 +00:00
Fergus Henderson
e1ba75906b When reporting errors for undefined symbols, check for parent modules
Estimated hours taken: 8
Branches: main

compiler/typecheck.m:
	When reporting errors for undefined symbols, check for parent modules
	which are not imported, and print an extra message about those.
	Also make a bit more use of error_util.m.

tests/invalid/Mmakefile:
tests/invalid/missing_parent_import.m:
tests/invalid/missing_parent_import.err_exp:
tests/invalid/children.m:
tests/invalid/children2.m:
	A regression test.

tests/invalid/transitive_import_class.err_exp:
	Change the expected output to reflect line wrapping done by the
	new use of error_util.m.
2002-03-25 21:13:30 +00:00
Simon Taylor
d74eb22905 Fix a bug in the module import mechanism -- use_module should
Estimated hours taken: 8

Fix a bug in the module import mechanism -- use_module should
not be transitive. This change is needed for smart recompilation
to avoid needing to check whether the removal of a transitive
import could cause compilation errors -- it never should.

Also fix some bugs in the handling of type class declarations.

compiler/prog_data.m:
	Add a `transitively_imported' pseudo-declaration, which
	is placed before the items from `.int2' files and `.opt'
	files.

	Fix the representation of type class bodies.
	`:- typeclass foo where [].' declares a typeclass with no
	methods. `:- typeclass foo.' declares an abstract typeclass.
	The old representation made no distinction between these cases.

compiler/hlds_data.m:
compiler/prog_data.m:
compiler/module_qual.m:
	Move the declaration of type type_id from hlds_data.m to prog_data.m.
	This avoids a duplicate declaration in module_qual.m.

compiler/modules.m:
	Add a `transitively_imported' pseudo-declaration before the
	items from `.int2' files.

	Remove the bodies of typeclass declarations placed in `.int2'
	files -- the methods should not be available unless the module
	is explicitly imported.

compiler/module_qual.m:
	Items after the `transitively_imported' pseudo-declaration
	should not be considered when module qualifying locally
	declared items.

compiler/equiv_type.m:
compiler/mercury_to_mercury.m:
compiler/prog_io_typeclass.m:
	Handle the change to the representation of typeclass bodies.

compiler/prog_io_typeclass.m:
	Check that the arguments of a typeclass declaration
	are distinct variables.

compiler/make_hlds.m:
	Handle abstract typeclass declarations.

compiler/check_typeclass.m:
	Check that all typeclasses have a definition somewhere.

compiler/intermod.m:
	Write abstract_exported typeclasses to the `.opt' file.

compiler/add_trail_ops.m:
compiler/context.m:
compiler/llds.m:
compiler/vn_type.m:
	Add missing imports.

compiler/magic_util.m:
compiler/ml_type_gen.m:
	Remove unnecessary imports.

NEWS:
	Note that this change may break existing programs.

compiler/notes/todo.html:
	Remove the item relating to this change.

tests/invalid/transitive_import.{m,err_exp}:
	Add some tests for uses of transitively imported items.

tests/invalid/transitive_import_class.m:
tests/invalid/transitive_import_class2.m:
tests/invalid/transitive_import_class3.m:
tests/invalid/transitive_import_class.err_exp:
	Add a test for use of transitively imported class methods.

tests/invalid/invalid_typeclass.{m,err_exp}:
	Add some tests for invalid typeclass declarations.

tests/invalid/Mmakefile:
	Add the new tests.
2001-05-02 17:34:50 +00:00