Commit Graph

11 Commits

Author SHA1 Message Date
Zoltan Somogyi
8758df5518 Fix compiler abort on non-model_det procedures.
Github issue #118 reports a compiler abort that happens when
table_gen.m attempts to perform that transformation that implements
the tabling of I/O actions for declarative debugging, and a sanity check
finds that the procedure's determinism is not model_det.

We could change table_gen.m to not transform the affected predicate
in such cases. This change could fix *this specific* compiler abort,
but it is better to fix the root cause, which is that our semantic analysis
passes have not detected and reported a violation of our semantic rules,
and have allowed the affected predicate to flow through to the middle end
to be processed.

compiler/det_analysis.m:
compiler/det_report.m:
    We used to check whether predicates with I/O state arguments have
    one of the permitted model_det determinisms as part of det_infer_proc.
    Github issue #118 arose because det_infer_proc processes only
    predicates defined in the current module. It was also strange that
    some properties of mode declarations were checked by det_infer_proc
    in det_analysis.m (which can be invoked on a procedure more than once
    during mode inference), while others were checked by
    check_determinism_of_procs in det_report.m (which is only ever invoked
    on a procedure once, at the end of determinism analysis).

    Move the checks on mode declarations all to det_report.m. Partly
    this is to fix the above code smell, but mainly so that we can add
    check_determinism_of_imported_procs, which performs the part of
    the job of check_determinism_of_procs that is appropriate for
    imported procedures.

    Make the error message for invalid mode declarations more specific
    by listing the given invalid determinism as well as the possible
    valid determinisms.

    To make the above possible without doing unnecessary checks on
    compiler-constructed procedures that are "born correct", separate out
    imported procedures from born-correct procedures. Previously, they
    were lumped together as "no inference needed" procedures.

tests/invalid/ho_unique_error.err_exp:
tests/invalid/mostly_uniq1.err_exp:
tests/invalid/mostly_uniq2.err_exp:
    Expect the extra detail in error messages.

tests/invalid/io_in_ite_cond.err_exp:
tests/invalid/magicbox.err_exp:
tests/invalid/try_detism.err_exp:
    Expect an error message about the invalid determinism of a procedure
    with I/O state args. Previously, we did not generate an error message
    for these issues.
2023-03-16 16:27:03 +11:00
Zoltan Somogyi
209c546a77 Explain the components of determinism error msgs.
compiler/det_report.m:
    When we report that a predicate does not satisfy the requirements
    of its determinism declaration, we follow that statement with a list
    of statements about pieces of code that all contribute to that mismatch.
    However, a thread on m-users last month showed that some users did not
    make that connection. So add an explicit statement to that effect.

tests/invalid/bug150.err_exp:
tests/invalid/bug496.err_exp:
tests/invalid/det_atomic_goal_msgs.err_exp:
tests/invalid/det_errors.err_exp:
tests/invalid/magicbox.err_exp:
tests/invalid/not_a_switch.err_exp:
tests/invalid/try_detism.err_exp:
tests/invalid/user_field_access_decl_override.err_exp:
    Expect updated error messages.
2021-08-27 21:57:01 +10:00
Zoltan Somogyi
3dc4babb24 Update the style of more test cases.
And update expected output files for changes in line numbers.
2021-07-27 13:29:46 +10:00
Zoltan Somogyi
f564e463b4 Print the causes of unmet determinism requirements.
compiler/det_report.m:
    When a scope that requires a goal to have a certain determinism doesn't,
    don't just print a message saying there is a mismatch between the actual
    and required determinisms; also print the cause of that mismatch.

    Fix a case error in an error message.

tests/invalid/det_atomic_goal_msgs.err_exp:
tests/invalid/magicbox.err_exp:
tests/invalid/require_det_in_lambda.err_exp:
tests/invalid/require_scopes.err_exp:
    Expect the compiler's newly expanded and fixed output.
2015-03-12 03:28:49 +11: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
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
Zoltan Somogyi
f9fe8dcf61 Improve the error messages generated for determinism errors involving committed
Estimated hours taken: 8
Branches: main

Improve the error messages generated for determinism errors involving committed
choice contexts. Previously, we printed a message to the effect that e.g.
a cc pred is called in context that requires all solutions, but we didn't say
*why* the context requires all solutions. We now keep track of all the goals
to the right that could fail, since it is these goals that may reject the first
solution of a committed choice goal.

The motivation for this diff was the fact that I found that locating the
failing goal can be very difficult if the conjunction to the right is
a couple of hundred lines long. This would have been a nontrivial problem,
since (a) unifications involving values of user-defined types are committed
choice goals, and (b) we can expect uses of user-defined types to increase.

compiler/det_analysis.m:
	Keep track of goals to the right of the current goal that could fail,
	and include them in the error representation if required.

compiler/det_report.m:
	Include the list of failing goals to the right in the representations
	of determinism errors involving committed committed choice goals.

	Convert the last part of this module that wasn't using error_util
	to use error_util. Make most parts of this module just construct
	error message specifications; print those specifications (using
	error_util) in only a few places.

compiler/hlds_out.m:
	Add a function for use by the new code in det_report.m.

compiler/error_util.m:
	Add a function for use by the new code in det_report.m.

compiler/error_util.m:
compiler/compiler_util.m:
	Error_util is still changing reasonably often, and yet it is
	included in lots of modules, most of which need only a few simple
	non-parse-tree-related predicates from it (e.g. unexpected).
	Move those predicates to a new module, compiler_util.m. This also
	eliminates some undesirable dependencies from libs to parse_tree.

compiler/libs.m:
	Include compiler_util.m.

compiler/notes/compiler_design.html:
	Document compiler_util.m, and fix the documentation of some other
	modules.

compiler/*.m:
	Import compiler_util instead of or in addition to error_util.
	To make this easier, consistently use . instead of __ for module
	qualifying module names.

tests/invalid/det_errors_cc.{m,err_exp}:
	Add this new test case to test the error messages for cc contexts.

tests/invalid/det_errors_deet.{m,err_exp}:
	Add this new test case to test the error messages for unifications
	inside function symbols.

tests/invalid/Mmakefile:
	Add the new test cases.

tests/invalid/det_errors.err_exp:
tests/invalid/magicbox.err_exp:
	Change the expected output to conform to the change in det_report.m,
	which is now more consistent.
2005-10-28 02:11:03 +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
Zoltan Somogyi
b2961048d8 Fix a problem reported by Ralph.
Estimated hours taken: 0.3
Branches: main

Fix a problem reported by Ralph.

compiler/det_analysis.m:
	Complain about bad determinisms for predicates with I/O states only if
	the predicate is declared with a bad determinism or doesn't have any
	declared determinism. Don't complain if the declared determinism is OK
	even if the inferred determinism isn't, since in that case the root of
	the problem lies elsewhere, and other error messages will point it out.

tests/invalid/magic_box.err_exp:
	Update the expected output of this test case.
2004-06-24 07:57:44 +00:00
Zoltan Somogyi
bc56e927b6 Detect when a predicate has a pair of I/O states but isn't det or cc_multi.
Estimated hours taken: 6
Branches: main

Detect when a predicate has a pair of I/O states but isn't det or cc_multi.
Improve the generation of determinism error messages.

compiler/det_analysis.m:
	Detect when a predicate has a pair of I/O states but isn't det or
	cc_multi.

	Factor out some common code.

compiler/det_report.m:
	Add the new error type for predicates with I/O states.

	Use error_util much more extensively to generate error messages.

compiler/hlds_out.m:
	For several existing predicates that write out various HLDS
	constructs, provide versions that return representations of those
	constructs as strings or as error_util pieces, for use by det_report.m.
	Redefine the old predicates as simply printing the output of the new
	predicates where relevant, to avoid code duplication.

compiler/error_util.m:
	When describing a predicate name, specify whether we want to module
	qualify the name or not. The intention is that when generating a kind
	of error message which can only be generated for predicates defined
	in the current module, the module prefix should be omitted in the
	interest of clarity.

compiler/accumulator.m:
compiler/dead_proc_elim.m:
compiler/magic_util.m:
compiler/table_gen.m:
compiler/term_errors.m:
compiler/termination.m:
compiler/typecheck.m:
	Conform to the changes in error_util.m.

compiler/globals.m:
	Reorder arguments to allow the use of state variable notation.

compiler/handle_globals.m:
compiler/mercury_compile.m:
compiler/source_file_map.m:
	Conform to the changed argument order in globals.m.

tests/invalid/aditi_update_errors.err_exp:
tests/invalid/errors2.err_exp2:
tests/invalid/external.err_exp:
tests/invalid/ho_unique_error.err_exp:
tests/invalid/magicbox.err_exp:
tests/invalid/missing_det_decls.err_exp:
tests/invalid/mostly_uniq1.err_exp:
tests/invalid/mostly_uniq2.err_exp:
tests/invalid/multimode_syntax.err_exp:
tests/invalid/multisoln_func.err_exp:
tests/invalid/pragma_c_code_dup_var.err_exp:
tests/invalid/pragma_c_code_no_det.err_exp:
tests/invalid/prog_io_erroneous.err_exp2:
tests/invalid/qualified_cons_id2.err_exp:
tests/invalid/record_syntax_errors.err_exp:
tests/invalid/state_vars_test1.err_exp:
tests/invalid/state_vars_test2.err_exp:
tests/invalid/state_vars_test3.err_exp:
tests/invalid/typeclass_mode.err_exp:
tests/invalid/types.err_exp2:
tests/invalid/undef_mode_and_no_clauses.err_exp:
tests/recompilation/typeclass_method_pragma_r.err_exp.2:
tests/warnings/ambiguous_overloading.exp:
tests/warnings/duplicate_call.exp:
tests/warnings/duplicate_const.exp:
tests/warnings/infinite_recursion.exp:
tests/warnings/simple_code.exp:
tests/warnings/warn_dead_procs.exp:
tests/warnings/warn_stubs.exp:
	Update these files to expect the better error messages we now generate.
2004-05-14 08:40:33 +00:00
Zoltan Somogyi
44f001e26f Fix an overly strong sanity check, at least temporarily.
Estimated hours taken: 1
Branches: main

compiler/det_analysis.m:
	Fix an overly strong sanity check, at least temporarily.

tests/invalid/magicbox.m:
	Add the test case motivating that change.

tests/invalid/MMakefile
	Enable the new test.
2004-04-01 04:32:42 +00:00