Commit Graph

20 Commits

Author SHA1 Message Date
Zoltan Somogyi
c53f9ab46e Don't output lines that end with a space.
compiler/write_error_spec.m:
    When error_specs include blank lines, we used to output lines
    of the form "filename:linenumber: ". Stop generating the final space.

compiler/parse_tree_out_misc.m:
    Add a new version of an existing function.

tests/invalid/actual_more_expected.err_exp:
tests/invalid/ambiguous_overloading_error.err_exp:
tests/invalid/any_passed_as_ground.err_exp:
tests/invalid/anys_in_negated_contexts.err_exp:
tests/invalid/bad_ambiguity_msg.err_exp:
tests/invalid/bug150.err_exp:
tests/invalid/bug150_partial_color.err_exp:
tests/invalid/bug496.err_exp:
tests/invalid/det_atomic_goal_msgs.err_exp:
tests/invalid/det_errors.err_exp:
tests/invalid/det_errors_and_io.err_exp:
tests/invalid/det_errors_deep.err_exp:
tests/invalid/ho_default_func_1.err_exp:
tests/invalid/ho_default_func_3.err_exp:
tests/invalid/ho_default_func_4.err_exp:
tests/invalid/ho_type_mode_bug.err_exp:
tests/invalid/magicbox.err_exp:
tests/invalid/max_error_line_width.err_exp:
tests/invalid/mode_inf.err_exp:
tests/invalid/modes_erroneous.err_exp:
tests/invalid/no_ho_inst.err_exp:
tests/invalid/not_a_switch.err_exp:
tests/invalid/state_vars_test_1.err_exp:
tests/invalid/try_detism.err_exp:
tests/invalid/user_field_access_decl_override_1.err_exp:
tests/invalid_nodepend/errors_2.err_exp:
tests/warnings/ambiguous_overloading.err_exp:
tests/warnings/inconsistent_pred_order.err_exp:
tests/warnings/subtype_order.err_exp:
tests/warnings/test_tscp.err_exp:
    Stop expecting a final space.
2025-09-15 06:28:07 +10:00
Zoltan Somogyi
4dd8669a87 Don't include irrelevant arg modes in diagnostics.
compiler/hlds_error_util.m:
    When creating format_pieces identifying one procedure of a predicate
    or function, use just the id of the predicate or function itself
    if it has no other procedures. This avoids cluttering diagnostics
    with irrelevant details.

    Replace two separate functions that used to construct such ids with one.
    The difference was that one got the actual arg modes from a pred_info,
    while the other allowed the caller to supply any modes it wanted, but
    all callers (except one) of the second variant got the arg modes
    the exact same way the first variant did. The one exception got them
    from the *declared* arg modes field of the pred_info, which was a bug,
    because would have generated unusable output if the predicate or function
    had no declared modes, and got all its modes by inference.

    Put all the functions involved in all of the above into a logical order.

compiler/det_analysis.m:
compiler/det_report.m:
compiler/simplify_goal_call.m:
compiler/stratify.m:
    Conform to the changes in hlds_error_util.m.

    In some places, improve diagnostics in other ways as well.

tests/general/Mercury.options:
tests/general/Mmakefile:
tests/warnings/Mmakefile:
tests/warnings/petdr1.{m,err_exp}:
    Move the petdr1 test case from general to warnings. This case
    never generated any output; its intended use was to check for
    the absence of a compiler abort in the generation of some warnings.
    In its new home, it tests that *and* the texts of the warnings.

tests/invalid/bug150.err_exp:
tests/invalid/bug150_partial_color.err_exp:
tests/invalid/bug496.err_exp:
tests/invalid/det_atomic_goal_msgs.err_exp:
tests/invalid/det_errors.err_exp:
tests/invalid/det_errors_and_io.err_exp:
tests/invalid/det_errors_deep.err_exp:
tests/invalid/erroneous_throw_promise.err_exp:
tests/invalid/hawkins_mm_fail_reset.err_exp:
tests/invalid/ho_unique_error.err_exp:
tests/invalid/io_in_ite_cond.err_exp:
tests/invalid/loopcheck.err_exp:
tests/invalid/magicbox.err_exp:
tests/invalid/mostly_uniq_1.err_exp:
tests/invalid/mostly_uniq_2.err_exp:
tests/invalid/multisoln_func.err_exp:
tests/invalid/not_a_switch.err_exp:
tests/invalid/one_member.err_exp:
tests/invalid/pragma_c_code_no_det.err_exp:
tests/invalid/ref_to_implicit_comma.err_exp:
tests/invalid/ref_to_implicit_pred.err_exp:
tests/invalid/require_det_in_lambda.err_exp:
tests/invalid/require_scopes.err_exp:
tests/invalid/try_detism.err_exp:
tests/invalid/user_field_access_decl_override_1.err_exp:
tests/invalid_nodepend/invalid_main.err_exp:
tests/invalid_nodepend/occurs.err_exp:
tests/warnings/det_infer_warning.err_exp:
tests/warnings/non_stratification.err_exp:
tests/warnings/obsolete_proc_pragma.err_exp:
    Expect the updated diagnostics.
2025-01-10 16:45:10 +11:00
Zoltan Somogyi
c7a72fee02 Add a blank before "possible reason" messages.
Mode analysis and determinism analysis can generate error_specs that
have long had the form:

    context1:   There was a problem with X. The following messages give
    context1:    possible reasons for this problem.
    context2:   Possible reason 1.
    context3:   Possible reason 2.

This diff adds a line containing only a context before every reason, yielding
this modified output:

    context1:   There was a problem with X. The following messages give
    context1:    possible reasons for this problem.
    context2:
    context2:   Possible reason 1.
    context3:
    context3:   Possible reason 2.

The new layout makes it significantly easier for readers to find
where each reason's description begins, especially when a single reason's
description itself takes several lines.

compiler/error_spec.m:
    Add a new kind of error_msg for the new lines, which are blank
    except possibly (usually) for a context.

    Move a utility predicate here from error_sort.m, to make it available
    to error_util.m.

compiler/error_util.m:
    Add a predicate that prefaces each reason's error_msg with the new
    blank line error_msg.

compiler/write_error_spec.m:
    Implement the new kind of error_msg.

compiler/det_report.m:
compiler/mode_errors.m:
    Use the new capability in the error_specs that list possible reasons
    for a problem.

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

    Delete a predicate moved to error_spec.

tests/invalid/bug150.err_exp:
tests/invalid/bug150_partial_color.err_exp:
tests/invalid/bug496.err_exp:
tests/invalid/det_atomic_goal_msgs.err_exp:
tests/invalid/det_errors.err_exp:
tests/invalid/det_errors_and_io.err_exp:
tests/invalid/det_errors_deep.err_exp:
tests/invalid/magicbox.err_exp:
tests/invalid/mode_inf.err_exp:
tests/invalid/not_a_switch.err_exp:
tests/invalid/try_detism.err_exp:
tests/invalid/user_field_access_decl_override_1.err_exp:
    Expect updated diagnostics.
2024-10-01 13:34:26 +02:00
Zoltan Somogyi
13541a34c9 Standardize the format of lists of cons_ids.
compiler/det_report.m:
    Use the standard utility function to format item-per-line lists.

tests/invalid/det_errors.err_exp:
    Update the expected output of this test.
2024-05-22 22:19:35 +10:00
Zoltan Somogyi
e1472c8b07 More minor updates to diagnostics.
compiler/det_report.m:
    Use color more sparingly, especially the possible_cause color.
    Replace some, but far from all, of its uses with color_correct
    and color_incorrect.

    Improve wording.

    Fix an old design choice that worked only by accident. When we diagnose
    a procedure body goal as not meeting the determinism promises made by
    its declaration, we print reports for each goal that contributes
    to that promise being broken. We want those reports to appear in
    the order of their appearance in the source code, so we sort them,
    which was intended to sort the error_msgs by their context fields
    (which is the first field in error_msgs specifically to make this
    possible).

    The problem was that the report we generated for one promise-breaking
    goal could, and often did, consist of several error_msgs. Since these
    error_msgs all have the same context, the context of the goal,
    it was pure luck that the sorting preserved the relative order of these
    error_msgs. With the changes made by this diff to improve wording,
    this lucky streak ran out. This diff therefore changes things so that
    we generate only one error_msg for each promise-breaking goal.

compiler/parse_util.m:
    Add more color to one diagnostic to follow our usual scheme.

compiler/parse_type_defn.m:
compiler/parse_inst_mode_defn.m:
    Keep the messages for uses of reserved type/inst/mode names in sync.

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/det_errors_and_io.err_exp:
tests/invalid/hawkins_mm_fail_reset.err_exp:
tests/invalid/loopcheck.err_exp:
tests/invalid/magicbox.err_exp:
tests/invalid/not_a_switch.err_exp:
tests/invalid/one_member.err_exp:
tests/invalid/pragma_c_code_no_det.err_exp:
tests/invalid/ref_to_implicit_comma.err_exp:
tests/invalid/ref_to_implicit_pred.err_exp:
tests/invalid/require_det_in_lambda.err_exp:
tests/invalid/require_scopes.err_exp:
tests/invalid/require_switch_arms_detism.err_exp:
tests/invalid/switch_arm_multi_not_det.err_exp:
tests/invalid/try_detism.err_exp:
tests/invalid/user_field_access_decl_override_1.err_exp:
tests/invalid_nodepend/bad_inst_defn.err_exp:
tests/invalid_nodepend/invalid_main.err_exp:
tests/invalid_nodepend/invalid_typeclass.err_exp:
tests/invalid_nodepend/occurs.err_exp:
tests/invalid_nodepend/reserved.err_exp:
tests/invalid_nodepend/reserved_type_name.err_exp:
tests/invalid_nodepend/subtype_syntax.err_exp:
tests/warnings/det_infer_warning.err_exp:
    Expect updated diagnostics.
2024-05-22 16:09:45 +10:00
Zoltan Somogyi
0fa51cc45c Use color in typecheck_error_undef.m ...
... and change the coloring done in many other modules.

compiler/typecheck_error_undef.m:
    Add color to the diagnostics generated by this module.

    In a few cases, improve the wording of the diagnostic.

    Make the name of a function and of a function symbol more descriptive.

    Convert some predicates from using many clauses to using
    an explicit disjunction.

    Delete a function that was sort-of a specialize version of a
    utility function in error_spec.m.

compiler/hlds_error_util.m:
    Change the functions that return descriptions of predicates and procedures,
    mostly for use in diagnostics, to allow the parts of those descriptions
    specific to an individual predicate or procedure to be colored *without*
    coloring the generic parts (such as the word "predicate" or "function").

    Add simpler versions of the affected functions for use cases that
    do not need any coloring.

compiler/accumulator.m:
compiler/add_clause.m:
compiler/add_pragma.m:
compiler/check_pragma_format_call.m:
compiler/check_typeclass.m:
compiler/dead_proc_elim.m:
compiler/det_analysis.m:
compiler/det_report.m:
compiler/direct_arg_in_out.m:
compiler/fact_table.m:
compiler/float_regs.m:
compiler/format_call.m:
compiler/hlds_out_module.m:
compiler/hlds_statistics.m:
compiler/inst_mode_type_prop.m:
compiler/make_hlds_error.m:
compiler/mode_errors.m:
compiler/modes.m:
compiler/oisu_check.m:
compiler/old_type_constraints.m:
compiler/ordering_mode_constraints.m:
compiler/parse_module.m:
compiler/post_typecheck.m:
compiler/prop_mode_constraints.m:
compiler/purity.m:
compiler/simplify_goal_call.m:
compiler/stratify.m:
compiler/style_checks.m:
compiler/table_gen.m:
compiler/tabling_analysis.m:
compiler/term_constr_errors.m:
compiler/term_errors.m:
compiler/termination.m:
compiler/trailing_analysis.m:
compiler/typecheck.m:
compiler/typecheck_clauses.m:
compiler/typecheck_error_overload.m:
compiler/typecheck_error_util.m:
compiler/typecheck_errors.m:
compiler/typecheck_msgs.m:
    Conform to the changes in hlds_error_util.m.

    In many cases, improve the affected diagnostics, and maybe other nearby
    diagnostics, in other ways as well.

compiler/hlds_data.m:
    Fix comments.

tests/invalid/bad_exported_mode.err_exp:
tests/invalid/bad_fact_table_data.err_exp:
tests/invalid/bad_fact_table_data.err_exp2:
tests/invalid/bad_fact_table_decls.err_exp:
tests/invalid/bad_format_call.err_exp:
tests/invalid/bad_pred_arity.err_exp:
tests/invalid/bad_sv_unify_msg.err_exp:
tests/invalid/bug10.err_exp:
tests/invalid/bug113.err_exp:
tests/invalid/bug150.err_exp:
tests/invalid/bug184.err_exp:
tests/invalid/bug197.err_exp:
tests/invalid/bug214.err_exp:
tests/invalid/bug238.err_exp:
tests/invalid/bug257.err_exp:
tests/invalid/bug476.err_exp:
tests/invalid/bug496.err_exp:
tests/invalid/builtin_proc.err_exp:
tests/invalid/coerce_syntax.err_exp:
tests/invalid/coerce_void.err_exp:
tests/invalid/constructor_warning.err_exp:
tests/invalid/det_atomic_goal_msgs.err_exp:
tests/invalid/det_errors.err_exp:
tests/invalid/det_errors_and_io.err_exp:
tests/invalid/det_errors_cc.err_exp:
tests/invalid/erroneous_throw_promise.err_exp:
tests/invalid/exist_foreign_error.err_exp:
tests/invalid/exported_mode.err_exp:
tests/invalid/exported_unify.err_exp:
tests/invalid/field_syntax_error.err_exp:
tests/invalid/foreign_purity_mismatch.err_exp:
tests/invalid/foreign_purity_mismatch.err_exp2:
tests/invalid/foreign_purity_mismatch.err_exp3:
tests/invalid/foreign_type_2.err_exp:
tests/invalid/freefree.err_exp:
tests/invalid/getopt_io_old.err_exp:
tests/invalid/getopt_old_se.err_exp:
tests/invalid/gh72_errors.err_exp:
tests/invalid/hawkins_mm_fail_reset.err_exp:
tests/invalid/ho_unique_error.err_exp:
tests/invalid/impure_method_impl.err_exp:
tests/invalid/invalid_event.err_exp:
tests/invalid/invalid_new.err_exp:
tests/invalid/io_in_ite_cond.err_exp:
tests/invalid/loopcheck.err_exp:
tests/invalid/magicbox.err_exp:
tests/invalid/make_opt_error.err_exp:
tests/invalid/method_impl.err_exp:
tests/invalid/missing_det_decls.err_exp:
tests/invalid/mode_decl_in_wrong_section.err_exp:
tests/invalid/mostly_uniq1.err_exp:
tests/invalid/mostly_uniq2.err_exp:
tests/invalid/multimode_missing_impure.err_exp:
tests/invalid/multimode_syntax.err_exp:
tests/invalid/multiply_star.err_exp:
tests/invalid/no_method.err_exp:
tests/invalid/not_a_switch.err_exp:
tests/invalid/one_member.err_exp:
tests/invalid/pragma_c_code_dup_var.err_exp:
tests/invalid/pragma_c_code_no_det.err_exp:
tests/invalid/pragma_c_code_no_det.err_exp2:
tests/invalid/pragma_c_code_no_det.err_exp3:
tests/invalid/pragma_qual_error.err_exp:
tests/invalid/qual_basic_test2.err_exp:
tests/invalid/qualified_cons_id2.err_exp:
tests/invalid/quant_constraint_1.err_exp:
tests/invalid/quant_constraint_2.err_exp:
tests/invalid/record_syntax_errors.err_exp:
tests/invalid/ref_to_implicit_comma.err_exp:
tests/invalid/ref_to_implicit_pred.err_exp:
tests/invalid/spurious_mode_error.err_exp:
tests/invalid/state_vars_test_3.err_exp:
tests/invalid/string_format_bad.err_exp:
tests/invalid/string_format_unknown.err_exp:
tests/invalid/test_promise_equivalent_clauses.err_exp:
tests/invalid/test_type_spec.err_exp:
tests/invalid/transitive_import_class.err_exp:
tests/invalid/try_detism.err_exp:
tests/invalid/type_error_use_module.err_exp:
tests/invalid/type_inf_loop.err_exp:
tests/invalid/typeclass_dup_method_mode.err_exp:
tests/invalid/typeclass_mode_2.err_exp:
tests/invalid/typeclass_mode_3.err_exp:
tests/invalid/typeclass_mode_4.err_exp:
tests/invalid/typeclass_test_8.err_exp:
tests/invalid/types2.err_exp:
tests/invalid/undeclared_mode.err_exp:
tests/invalid/undef_mode_and_no_clauses.err_exp:
tests/invalid/undef_symbol.err_exp:
tests/invalid/unsatisfiable_constraint.err_exp:
tests/invalid/user_field_access_decl_override_1.err_exp:
tests/invalid/wrong_arity_function.err_exp:
tests/invalid_make_int/bad_end_module.int_err_exp:
tests/invalid_make_int/missing_initial_section.int_err_exp:
tests/invalid_nodepend/after_end_module.err_exp:
tests/invalid_nodepend/bad_fact_table.err_exp:
tests/invalid_nodepend/bigtest.err_exp:
tests/invalid_nodepend/bug410.err_exp:
tests/invalid_nodepend/constrained_poly_insts.err_exp:
tests/invalid_nodepend/duplicate_modes.err_exp:
tests/invalid_nodepend/errors_1.err_exp:
tests/invalid_nodepend/errors_2.err_exp:
tests/invalid_nodepend/errors_3.err_exp:
tests/invalid_nodepend/external.err_exp:
tests/invalid_nodepend/funcs_as_preds.err_exp:
tests/invalid_nodepend/impl_def_literal_syntax.err_exp:
tests/invalid_nodepend/invalid_binary_literal.err_exp:
tests/invalid_nodepend/invalid_decimal_literal.err_exp:
tests/invalid_nodepend/invalid_float_literal.err_exp:
tests/invalid_nodepend/invalid_hex_literal.err_exp:
tests/invalid_nodepend/invalid_main.err_exp:
tests/invalid_nodepend/invalid_octal_literal.err_exp:
tests/invalid_nodepend/no_exports.err_exp:
tests/invalid_nodepend/null_char.err_exp:
tests/invalid_nodepend/occurs.err_exp:
tests/invalid_nodepend/pragma_export.err_exp:
tests/invalid_nodepend/prog_io_erroneous.err_exp:
tests/invalid_nodepend/reserved_type_name.err_exp:
tests/invalid_nodepend/test_with_type.err_exp:
tests/invalid_nodepend/typeclass_test_1.err_exp:
tests/invalid_nodepend/typeclass_test_2.err_exp:
tests/invalid_nodepend/types.err_exp:
tests/invalid_nodepend/unbound_type_vars.err_exp:
tests/invalid_nodepend/unterminated_octal_escape.err_exp:
tests/invalid_nodepend/vars_in_wrong_places.err_exp:
tests/invalid_purity/impure_func_t2.err_exp:
tests/invalid_purity/impure_func_t3.err_exp:
tests/invalid_purity/impure_func_t4.err_exp:
tests/invalid_purity/pragma_c_and_mercury.err_exp:
tests/invalid_purity/purity.err_exp:
tests/invalid_purity/purity_nonsense_1.err_exp:
tests/invalid_purity/purity_nonsense_2.err_exp:
tests/invalid_submodules/exported_unify3.err_exp:
tests/invalid_submodules/func_class.err_exp:
tests/invalid_submodules/undef_mod_qual.err_exp:
tests/recompilation/typeclass_method_pragma_r.err_exp.2:
tests/recompilation/with_type_re.err_exp.2:
tests/warnings/arg_order_rearrangment.err_exp:
tests/warnings/bug477.err_exp:
tests/warnings/det_infer_warning.err_exp:
tests/warnings/disabled_warning.err_exp:
tests/warnings/foreign_term_invalid.err_exp:
tests/warnings/format_call_multi.err_exp:
tests/warnings/format_call_warning.err_exp:
tests/warnings/infinite_recursion.err_exp:
tests/warnings/non_contiguous_decls.err_exp:
tests/warnings/non_stratification.err_exp:
tests/warnings/obsolete_proc_pragma.err_exp:
tests/warnings/pragma_term_conflict.err_exp:
tests/warnings/purity_warnings.err_exp:
tests/warnings/save.err_exp:
tests/warnings/simple_code.err_exp:
tests/warnings/singleton_test.err_exp:
tests/warnings/spurious_obsolete.err_exp:
tests/warnings/suspicious_recursion.err_exp:
tests/warnings/unneeded_mode_specific_clause.err_exp:
tests/warnings/unsigned_zero_cmp.err_exp:
tests/warnings/warn_dead_procs.err_exp:
tests/warnings/warn_dead_procs_trace.err_exp:
tests/warnings/warn_non_contiguous.err_exp:
tests/warnings/warn_non_contiguous_foreign.err_exp:
tests/warnings/warn_stubs.err_exp:
    Expect updated diagnostics.
2024-05-20 18:31:15 +10:00
Zoltan Somogyi
2fe108aa53 Color subjects in purity and detism errors.
compiler/purity.m:
    Use color to emphasize the subject variables and terms of purity errors.

compiler/det_report.m:
    Use color to emphasize the subject variables and terms of determinism
    errors.

    Make the determinism test on main/2 require the determinism to be
    declared explicitly.

    Generate a diagnostic if main/2 to be not exported.

    Don't color connectives such as "or" between two colored words.

    Improve the wording of some error messages.

compiler/hlds_error_util.m:
    Replace the generic descriptions we used to generate for the
    predicates/functions implementing methods in typeclasses and in instances
    with descriptions that specify the method name.

tests/invalid/bug257.err_exp:
tests/invalid/det_errors.err_exp:
tests/invalid/foreign_purity_mismatch.err_exp:
tests/invalid/ho_unique_error.err_exp:
tests/invalid/impure_method_impl.err_exp:
tests/invalid/io_in_ite_cond.err_exp:
tests/invalid/method_impl.err_exp:
tests/invalid/mostly_uniq1.err_exp:
tests/invalid/mostly_uniq2.err_exp:
tests/invalid/multimode_missing_impure.err_exp:
tests/invalid/multisoln_func.err_exp:
tests/invalid/no_method.err_exp:
tests/invalid/require_complete_nested_switch.err_exp:
tests/invalid/require_scopes.err_exp:
tests/invalid/require_switch_arms_detism.err_exp:
tests/invalid/switch_arm_multi_not_det.err_exp:
tests/invalid/test_promise_equivalent_clauses.err_exp:
tests/invalid/typeclass_dup_method_mode.err_exp:
tests/invalid/typeclass_test_8.err_exp:
tests/invalid_nodepend/invalid_main.err_exp:
tests/invalid_nodepend/no_exports.err_exp:
tests/invalid_purity/impure_func_t7.err_exp:
tests/invalid_purity/pragma_c_and_mercury.err_exp:
tests/invalid_purity/purity.err_exp:
tests/recompilation/typeclass_method_pragma_r.err_exp.2:
tests/warnings/purity_warnings.err_exp:
    Expect the updated diagnostics.
2024-05-07 16:25:03 +10:00
Zoltan Somogyi
66b309dcd4 Handle color changes next to prefixes/suffixes.
compiler/write_error_spec.m:
    Redesign the code we use to decide what text goes onto each line.
    The new design rests on these two new principles:

    - Representing the current word separately from the words before it
      on the line. This allows us to merge together an arbitrary number
      of prefixes, a plain word, and an arbitrary number of suffixes
      without the two additional passes that the old algorithm used
      to accomplish the same goal.

    - Representing the spaces between words *explicitly*. Together with
      the previous principle, this allows us to do case analyses of the
      possible configurations of text, spaces and color changes with
      significantly simpler code than was possible with the previous design.
      The new code is longer, but

      - it is easier to see both that it does the right thing in each
        of these situations, including interactions between prefixes and
        suffixes on the one hand and color changes on the other, and

      - it is easier to check that all possible combinations of the
        relevant circumstances have code to handle them.

compiler/typecheck_error_undef.m:
    Use the new capability by using color in arity mismatch reports,
    which have the form of "(4, should be 2, 3 or 5)", where the numbers,
    which are surrounded by two parentheses which are respectively
    a prefix and a suffix, are colored.

compiler/error_spec.m:
    Exclude from the list of pieces to be colored not just any final
    subsequence of newline pieces, but any initial subsequence of newlines
    as well. This avoids the output having lines which end in two consecutive
    color changes with nothing between them: the first of which switches
    to a color, and the second of which resets the current color to neutral.

library/cord.m:
library/list.m:
library/one_or_more.m:
library/ra_list.m:
    Add a predicate named is_non_empty, which does what its name says,
    to each of these modules. In cord.m, this is new functionality,
    which is now used by write_error_spec.m. In the other modules,
    this new predicate is a synonym for the existing predicate
    is_not_empty. These modules were in a minority; all other modules
    that had a predicate to test for nonemptyness named it is_noN_empty,
    not is_noT_empty.

NEWS.md:
    Announce the new is_non_empty predicates.

tests/invalid/constructor_warning.err_exp:
tests/invalid/getopt_io_old.err_exp:
tests/invalid/invalid_event.err_exp:
tests/invalid/no_method.err_exp:
tests/invalid/types2.err_exp:
tests/invalid/wrong_arity_function.err_exp:
    Expect the new colored output from typecheck_error_undef.m,
    without the extra spaces around parentheses that the version
    of write_error_spec.m before this diff would have put around them.

tests/invalid/bug117.err_exp:
tests/invalid/bug191.err_exp:
tests/invalid/bug415.err_exp:
tests/invalid/char_inst.err_exp:
tests/invalid/coerce_int.err_exp:
tests/invalid/coerce_mode_error.err_exp:
tests/invalid/coerce_recursive_type.err_exp:
tests/invalid/constrained_poly_insts2.err_exp:
tests/invalid/default_ho_inst.err_exp:
tests/invalid/det_errors.err_exp:
tests/invalid/det_errors_and_io.err_exp:
tests/invalid/functor_ho_inst_bad.err_exp:
tests/invalid/ho_type_mode_bug.err_exp:
tests/invalid/html.err_exp:
tests/invalid/merge_ground_any.err_exp:
tests/invalid/mode_error_arg_number.err_exp:
tests/invalid/partial_implied_mode.err_exp:
tests/invalid/polymorphic_unification.err_exp:
tests/invalid/require_scopes.err_exp:
tests/invalid/type_prop_into_inst.err_exp:
    Expect the absence of switches to a color followed IMMEDIATELY
    by a color reset, thanks to the update of error_spec.m.
2024-05-04 00:27:34 +10:00
Zoltan Somogyi
ce085c6b7e Use color in determinism diagnostics.
compiler/det_report.m:
    Use color in determinism diagnostics.

compiler/error_spec.m:
    Shorten the names of some functions, to allow calls to them
    to fit on one line more frequently.

compiler/typecheck_error_undef.m:
compiler/typecheck_errors.m:
compiler/typecheck_msgs.m:
    Conform to the change in error_spec.m.

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/det_errors_and_io.err_exp:
tests/invalid/hawkins_mm_fail_reset.err_exp:
tests/invalid/ho_unique_error.err_exp:
tests/invalid/io_in_ite_cond.err_exp:
tests/invalid/loopcheck.err_exp:
tests/invalid/magicbox.err_exp:
tests/invalid/mostly_uniq1.err_exp:
tests/invalid/mostly_uniq2.err_exp:
tests/invalid/not_a_switch.err_exp:
tests/invalid/one_member.err_exp:
tests/invalid/pragma_c_code_no_det.err_exp:
tests/invalid/qualified_cons_id2.err_exp:
tests/invalid/ref_to_implicit_comma.err_exp:
tests/invalid/ref_to_implicit_pred.err_exp:
tests/invalid/require_det_in_lambda.err_exp:
tests/invalid/require_scopes.err_exp:
tests/invalid/require_switch_arms_detism.err_exp:
tests/invalid/switch_arm_multi_not_det.err_exp:
tests/invalid/try_detism.err_exp:
tests/invalid/user_field_access_decl_override.err_exp:
tests/invalid_nodepend/invalid_main.err_exp:
tests/invalid_nodepend/occurs.err_exp:
tests/warnings/det_infer_warning.exp:
    Expect updated diagnostic output.
2024-04-29 17:51:54 +10:00
Zoltan Somogyi
c5fc9a929d Print the contexts of later disjuncts ...
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.
2022-12-04 23:33:37 +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
590b34cfac Fix some minor problems in reporting determinism errors.
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.
2016-05-13 05:48:47 +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
7f39b321b2 Improve the compiler's ability to deal with determinism errors, in three ways.
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.
2011-04-08 07:25:55 +00: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
87b03a3942 Fix a problem with the formatting of some error messages.
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.
2004-12-27 03:56:03 +00:00
Zoltan Somogyi
64b3e74266 A script to compare actual and expected error outputs from the
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.
1996-11-04 07:15:18 +00:00