Commit Graph

8 Commits

Author SHA1 Message Date
Zoltan Somogyi
75dc210ab3 Color subjects in mode errors.
compiler/mode_errors.m:
    Use color to emphasize the subject variables and terms of mode errors.

    Use color to emphasize disagreements as possible causes
    in a few more places.

    Require reporters of the "no matching mode" error to specify
    what the match was against. This is to allow us to generate
    better diagnostics. Note the things that should still be improved.

    Use the names of numbers (as in two, three etc) instead of their numeral
    versions.

    Improve the wording and/or the punctuation of some error messages.

compiler/inst_mode_type_prop.m:
    Use the names of numbers (as in two, three etc) instead of their numeral
    versions.

compiler/error_spec.m:
compiler/write_error_spec.m:
    Move two formerly private utility functions of write_error_spec.m
    to error_spec.m, and export them. One of them is now used in
    the modules above.

compiler/modecheck_call.m:
compiler/modecheck_goal.m:
compiler/modecheck_unify.m:
compiler/modecheck_util.m:
compiler/unique_modes.m:
    Pass around info about "what the match was against" for the change
    in mode_errors.m descrived above.

compiler/hlds_out_util.m:
    Improve variable name.

compiler/hlds_module.m:
    Add an XXX.

tests/invalid/any_mode.err_exp:
tests/invalid/any_passed_as_ground.err_exp:
tests/invalid/any_should_not_match_bound.err_exp:
tests/invalid/any_to_ground_in_ite_cond.err_exp:
tests/invalid/any_to_ground_in_ite_cond_nomax.err_exp:
tests/invalid/anys_in_negated_contexts.err_exp:
tests/invalid/bad_sv_unify_msg.err_exp:
tests/invalid/bind_in_negated.err_exp:
tests/invalid/bind_var_errors.err_exp:
tests/invalid/bug117.err_exp:
tests/invalid/bug191.err_exp:
tests/invalid/bug278.err_exp:
tests/invalid/bug415.err_exp:
tests/invalid/bug487.err_exp:
tests/invalid/char_inst.err_exp:
tests/invalid/coerce_clobbered.err_exp:
tests/invalid/coerce_disambig.err_exp:
tests/invalid/coerce_implied_mode.err_exp:
tests/invalid/coerce_instvar.err_exp:
tests/invalid/coerce_int.err_exp:
tests/invalid/coerce_mode_error.err_exp:
tests/invalid/coerce_mode_error2.err_exp:
tests/invalid/coerce_recursive_inst.err_exp:
tests/invalid/coerce_recursive_type.err_exp:
tests/invalid/coerce_uniq.err_exp:
tests/invalid/constrained_poly_insts2.err_exp:
tests/invalid/currying_multimode_func.err_exp:
tests/invalid/dcg_context.err_exp:
tests/invalid/default_ho_inst.err_exp:
tests/invalid/default_ho_inst_2.err_exp:
tests/invalid/freefree.err_exp:
tests/invalid/functor_ho_inst_bad.err_exp:
tests/invalid/functor_ho_inst_bad_2.err_exp:
tests/invalid/functor_ho_inst_bad_3.err_exp:
tests/invalid/ho_any_inst.err_exp:
tests/invalid/ho_default_func_1.err_exp:
tests/invalid/ho_default_func_2.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/ho_unique_error.err_exp:
tests/invalid/html.err_exp:
tests/invalid/inst_matches_final_bug.err_exp:
tests/invalid/invalid_integral_call_inst.err_exp:
tests/invalid/io_in_ite_cond.err_exp:
tests/invalid/merge_ground_any.err_exp:
tests/invalid/merge_inst_error.err_exp:
tests/invalid/mode_error_arg_number.err_exp:
tests/invalid/mode_inf.err_exp:
tests/invalid/modes_erroneous.err_exp:
tests/invalid/mostly_uniq1.err_exp:
tests/invalid/mostly_uniq2.err_exp:
tests/invalid/multimode_dcg.err_exp:
tests/invalid/no_ho_inst.err_exp:
tests/invalid/partial_implied_mode.err_exp:
tests/invalid/polymorphic_unification.err_exp:
tests/invalid/state_vars_test1.err_exp:
tests/invalid/state_vars_test5.err_exp:
tests/invalid/try_detism.err_exp:
tests/invalid/unify_mode_error.err_exp:
tests/invalid/uniq_modes.err_exp:
tests/invalid/uniq_neg.err_exp:
tests/invalid_nodepend/constrained_poly_insts.err_exp:
tests/invalid_nodepend/occurs.err_exp:
tests/invalid_purity/impure_func_t5_fixed.err_exp:
tests/invalid_purity/purity.err_exp:
tests/warnings/simple_code.err_exp:
tests/warnings/unify_f_g.err_exp:
    Expect the updated versions of diagnostics.
2024-05-07 10:11:11 +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
af90a1702c Use color in mode error diagnostics.m.
compiler/mode_errors.m:
    Add color to diagnostics about mode errors where appropriate.

compiler/error_spec.m:
    Fix an issue raised by the changes to mode_errors.m, which was that
    having a colored span end in two or more newline pieces led to
    an unnecessary seemingly blank line at the end. (The line actually
    contained escape sequences to first set a color, and to then reset colors,
    but none of that was visible.) The fix is to always add color resets
    *before* any final sequence of newline pieces in the span being colored.

compiler/error_msg_inst.m:
    Add a note to a comment.

tests/invalid/any_mode.err_exp:
tests/invalid/any_should_not_match_bound.err_exp:
tests/invalid/any_to_ground_in_ite_cond.err_exp:
tests/invalid/any_to_ground_in_ite_cond_nomax.err_exp:
tests/invalid/anys_in_negated_contexts.err_exp:
tests/invalid/bad_sv_unify_msg.err_exp:
tests/invalid/bind_in_negated.err_exp:
tests/invalid/bind_var_errors.err_exp:
tests/invalid/bug117.err_exp:
tests/invalid/bug191.err_exp:
tests/invalid/bug278.err_exp:
tests/invalid/bug415.err_exp:
tests/invalid/bug487.err_exp:
tests/invalid/char_inst.err_exp:
tests/invalid/coerce_clobbered.err_exp:
tests/invalid/coerce_disambig.err_exp:
tests/invalid/coerce_implied_mode.err_exp:
tests/invalid/coerce_instvar.err_exp:
tests/invalid/coerce_int.err_exp:
tests/invalid/coerce_mode_error.err_exp:
tests/invalid/coerce_mode_error2.err_exp:
tests/invalid/coerce_recursive_inst.err_exp:
tests/invalid/coerce_recursive_type.err_exp:
tests/invalid/coerce_uniq.err_exp:
tests/invalid/constrained_poly_insts2.err_exp:
tests/invalid/currying_multimode_func.err_exp:
tests/invalid/dcg_context.err_exp:
tests/invalid/default_ho_inst.err_exp:
tests/invalid/functor_ho_inst_bad.err_exp:
tests/invalid/functor_ho_inst_bad_2.err_exp:
tests/invalid/functor_ho_inst_bad_3.err_exp:
tests/invalid/ho_any_inst.err_exp:
tests/invalid/ho_default_func_2.err_exp:
tests/invalid/ho_type_mode_bug.err_exp:
tests/invalid/ho_unique_error.err_exp:
tests/invalid/html.err_exp:
tests/invalid/inst_matches_final_bug.err_exp:
tests/invalid/invalid_integral_call_inst.err_exp:
tests/invalid/io_in_ite_cond.err_exp:
tests/invalid/merge_ground_any.err_exp:
tests/invalid/merge_inst_error.err_exp:
tests/invalid/mode_error_arg_number.err_exp:
tests/invalid/modes_erroneous.err_exp:
tests/invalid/mostly_uniq1.err_exp:
tests/invalid/mostly_uniq2.err_exp:
tests/invalid/multimode_dcg.err_exp:
tests/invalid/no_ho_inst.err_exp:
tests/invalid/partial_implied_mode.err_exp:
tests/invalid/polymorphic_unification.err_exp:
tests/invalid/qualified_cons_id2.err_exp:
tests/invalid/state_vars_test5.err_exp:
tests/invalid/unify_mode_error.err_exp:
tests/invalid/uniq_modes.err_exp:
tests/invalid/uniq_neg.err_exp:
tests/invalid_nodepend/constrained_poly_insts.err_exp:
tests/invalid_nodepend/occurs.err_exp:
tests/invalid_purity/impure_func_t5_fixed.err_exp:
tests/invalid_purity/purity.err_exp:
tests/warnings/simple_code.exp:
tests/warnings/unify_f_g.exp:
    Expect colors in these diagnostics.
2024-04-30 19:27:32 +10:00
Zoltan Somogyi
ae5f8d4ce7 Don't add unneeded ()s around qualified sym_names.
compiler/parse_tree_out_sym_name.m:
    As above.

tests/invalid/*.err_exp:
tests/term/*.trans_opt_exp:
tests/warnings/test_tscp.exp:
    Update these files to expect the *absence* of unnecessary parentheses
    around sym_names.

tests/term/foreign_valid.m:
    Export some pragmas to avoid warnings that are irrelevant to the test.
2024-02-07 22:52:32 +11:00
Zoltan Somogyi
2028df3f20 Fix references to func results in a mode error.
compiler/mode_errors.m:
    If the argument whose instantiation we are complaining about is
    the result of a function, say so.

tests/invalid/mode_error_arg_number.{m,err_exp}:
    Add a test of this message.

tests/invalid/bug117.err_exp:
tests/invalid/coerce_int.err_exp:
tests/invalid/html.err_exp:
tests/invalid/inst_matches_final_bug.err_exp:
    Expect the correct reference to function results in these test cases.
2022-10-01 13:06:20 +10:00
Zoltan Somogyi
60783563cd Don't expand insts in inst names.
compiler/error_msg_inst.m:
    When the first occurrence of a named inst I2 is an argument of another
    named inst I1, do *not* expand I2 there. Instead, expand it one of its
    occurrences in the *expansion* of I1.

    To expand I2 at its *first* occurrence in the expansion of I1,
    change the way to format lists of insts to format the head inst
    before formatting the tail insts.

    Shorten a field name.

tests/invalid/html.err_exp:
    Expect the fix for the "omitted insts" bug above.
2022-02-06 08:29:19 +11:00
Zoltan Somogyi
52c0c52cfd Fix formatting when reporting problem insts.
compiler/error_msg_inst.m:
    Fix a bug that caused the suffix that all paths in two predicates
    were supposed to add at the logical end of the constructed pieces
    (though it could be followed by some punctuation) to *not* be added
    to the constructed pieces on some paths. Since with our current approach,
    the suffix for one inst in a list of insts can be the description
    of *all the insts following it in the list*, this bug could delete
    not just punctuation, but entire insts from the output. This did actually
    happen for the invalid/html text case below.

    Fix a problem that could cause each inst in a list of insts
    to be indented one more level than the previous inst, which can be
    very confusing.

    Delete the comma from "instname, which expands to ...". When this output
    occurs in an argument list, the presence of the comma can make it
    harder to recognize where one argument ends and the next argument begins.

    Factor out some common code.

    Add an XXX noting a problem.

    Fix documentation.

compiler/parse_tree_out_inst.m:
    Provide two functions for use by error_msg_inst.m.

compiler/prog_mode.m:
    Fix a comment.

tests/invalid/html.m:
    Fix the description of the problem we are testing for.

tests/invalid/html.err_exp:
    Expect the fix for the "omitted insts" bug above.

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/constrained_poly_insts2.err_exp:
tests/invalid/ho_default_func_4.err_exp:
tests/invalid/merge_ground_any.err_exp:
tests/invalid/polymorphic_unification.err_exp:
    Do not expect the deleted comma.
2022-02-05 19:40:51 +11:00
Zoltan Somogyi
4ebe95672d Don't crash on inst_name nested inside itself.
This fixes Mantis bug #528.

compiler/error_msg_inst.m:
    Since an inst_name IN may be used nested inside itself, as in
    IN(..., IN(...), ...), do not insist that both occurrences of IN
    in such cases lead to the insertion of a new entry in the inst name
    expansion map.

tests/invalid/html.{m,err_exp}:
    The Mantis test case.

tests/invalid/Mmakefile:
    Enable the Mantis test case.
2021-01-30 01:45:26 +11:00