compiler/det_report.m:
... when a "declared det, inferred multi" kind of determinism error
is caused by the (probably unexpected, possibly hard-to-see) presence
of a disjunction.
Change the wording to refer to "disjuncts" instead of "clauses";
while in Mercury, all clauses in multi-clause definitions are implicitly
also disjuncts, not all disjuncts are whole clauses.
tests/invalid/bug496.err_exp:
tests/invalid/det_errors.err_exp:
tests/invalid/not_a_switch.err_exp:
tests/invalid/require_scopes.err_exp:
tests/invalid/switch_arm_multi_not_det.err_exp:
Expect the updated form of the error message.
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.
compiler/det_report.m:
When a goal has too many solutions, but it occurs in a context in which
the identity of those solutions does not matter, the compiler inserts
a commit scope to prune away the redundant (because they are externally
indistinguishable) solutions.
When this goal is a switch inside a require_switch_arms_<detism> scope,
this commit scope added by determinism analysis screwed up the expectation
of the require_switch_arms_<detism> scope that the switch is its IMMEDIATE
subgoal. Relax this sometimes-wrong assumption by allowing for a commit
scope wrapped around the switch.
When generating error messages for cons_ids missing from switches,
don't print the module qualifiers for the cons_ids, since users
will already know it (it is part of the identity of the type of switch-on
variable).
Print the missing cons_ids one per line, to make the list easier to read.
Fix capitalization in some error messages.
compiler/switch_detection.m:
When creating switch arms, give each arm a more meaningful context
that the context of the original disjunction, which is usually the context
of the first ";" operator in it.
tests/invalid/switch_arm_multi_not_det.{m,err_exp}:
New test case for the fix listed first for det_report.m.
tests/invalid/Mmakefile:
Enable the new test case.
tests/debugger/dice.exp*:
tests/invalid/det_errors.err_exp:
tests/invalid/require_scopes.err_exp:
Update these expected outputs for the changes above.
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.
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.
Estimated hours taken: 4
Branches: main
Improve the compiler's ability to deal with determinism errors, in three ways.
1. Add a new pragma, no_determinism_warning, that suppresses the compiler's
warning about a determinism declaration that is not as tight as possible.
2. When printing determinism errors about disjunctions in supposed-to-be-det
code, print the list of switch arms that the disjunction is in. Without
this, it can be hard to find duplicated cases in a long list of switch
cases. (If the report tells you there is a disjunction in the arm for
f/1 in the switch on X, it tells you that you have duplicated the arm
for X = f(_).)
3. When the compiler prints a message about a switch on a variable not covering
some cases, sometimes the variable is an anonymous variable:
The switch on V_16 does not cover ...
These anonymous variables are created by common-structure elimination,
which groups disjuncts containing unifications such as A = f(a), A = f(b),
A = f(c) into a single arm of the switch on A, A = f(V_16), with a switch
inside that on V_16.
The third part of this diff gives the context of the error in the error
switch as not being the arm for f/1 in the switch on A, but as the arm for
f(V_16) in the switch on A, thus letting users know where the anonymous
variable comes from.
doc/reference_manual.texi:
Document the new pragma.
compiler/prog_item.m:
Add the new pragma to the list of pragmas we recognize.
compiler/hlds_pred.m:
Add the new kind of predicate marker whose presence indicates
that this pragma was given for this predicate.
compiler/prog_io_pragma.m:
Parse the new pragma.
compiler/add_pragma.m:
Process the new pragma: when found, set the marker on the named
predicate.
compiler/det_report.m:
Make all three changes listed above.
In addition, fix a problem that used to happen only rarely:
when printing switch contexts, we used to print them from the inside
out, not the outside in.
Capitalize only the first clause in a multi-clause error message.
compiler/hlds_out_util.m:
Add a function for printing a cons_id either with or without its
arguments, for use by det_report.m Let this function string module
qualifiers from cons_ids, since these are virtually always obvious,
and whose printing is therefore unnecessary clutter.
compiler/equiv_type.m:
compiler/hlds_out_pred.m:
compiler/make_hlds_passes.m:
compiler/mercury_to_mercury.m:
compiler/module_qual.m:
compiler/modules.m:
compiler/recompilation.version.m:
compiler/table_gen.m:
Conform to the changes above.
tests/invalid/det_errors.{m,err_exp}:
Add some predicates to this module to test the new functionality,
and update the expected output.
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.
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.
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.
Estimated hours taken: 0.5
Branches: main
compiler/det_report.m:
Fix a problem with the formatting of some error messages.
tests/invalid/det_errors.{m,exp}:
Add to this test case a test for the new fix.
Estimated hours taken: 0.5
runtests:
A script to compare actual and expected error outputs from the
compiler.
Mmake:
Don't test types.m, since we don't pass it, and lambda_type_bad,
since the tested code is no longer invalid.
*.err_exp:
The expected error outputs.