Files
mercury/samples/diff
Zoltan Somogyi 4aed1a57e4 Print an arg type list diff for arg lists with wrong arity.
When a user writes a clause for a predicate (or function) that does not exist
with that arity, but does exist with one or more other arities, report not
just the list of the other arity/arities, but, for each such other arity,
a diff between the declared arg types and the inferred arg types.

After this diff, we generate output like this:

bad_pred_arity.m:027: Error: clause for predicate `bad_pred_arity.p'/4
bad_pred_arity.m:027:   without corresponding `:- pred' declaration.
bad_pred_arity.m:027:   However, predicates of that name do exist with arities
bad_pred_arity.m:027:   3 and 5.
bad_pred_arity.m:027: Inferred :- pred p(int, string, int, string).
bad_pred_arity.m:027:   The argument list difference from the arity 3 version
bad_pred_arity.m:027:   is
bad_pred_arity.m:027:     pred(
bad_pred_arity.m:027:         int,
bad_pred_arity.m:027:   +     string,
bad_pred_arity.m:027:         int,
bad_pred_arity.m:027:         string
bad_pred_arity.m:027:     )
bad_pred_arity.m:027:   The argument list difference from the arity 5 version
bad_pred_arity.m:027:   is
bad_pred_arity.m:027:     pred(
bad_pred_arity.m:027:         int,
bad_pred_arity.m:027:   -     float,
bad_pred_arity.m:027:         string,
bad_pred_arity.m:027:         int,
bad_pred_arity.m:027:         string
bad_pred_arity.m:027:     )

compiler/typecheck_errors.m:
    Generate the diff part of the message above.

compiler/typecheck.m:
    Invoke typecheck_errors.m when relevant.

compiler/error_util.m:
    When comparing two error_specs, switch from a two-level comparison
    (first the contexts of error_msgs, then everything else) to three levels
    first the contexts of error_msgs, then their error_msg_components,
    then everything else). This is needed to allow the error message from
    make_hlds_error.m (which reports the error and mentions the arities
    with which the named predicate or function does exist) come out before
    the informational message from typecheck.m that prints the inferred
    arg types and their differences from the other arities. (With the old
    comparison, the difference in severity would trump the invisible order
    components that this diff includes in both specs to force the desire
    order.)

    Base the code comparing error_specs on the code for comparing error_msgs.
    Move the two previously separate pieces code for those tasks next to each
    other.

compiler/make_hlds_error.m:
    Add the invisble ordering component.

    When we see clauses with two or more wrong arities for a given predicate
    or function, don't list the automatically created pred declaration
    for an *earlier* wrong-arity clause as a real declaration whose arity
    is to be listed in the error messages we generate for *later* wrong-arity
    clauses.

    Add some documentation.

compiler/add_pred.m:
    Factor out some common code.

library/edit_seq.m:
    A new module for computing diffs.

library/library.m:
library/MODULES_DOC:
    Add the new module to the standard library.

tests/hard_coded/edit_seq_test.{m,exp}:
    A new test case for the diff algorithm.

tests/invalid/bad_pred_arity.{m,err_exp}:
    A new test case for the new error message.

tests/hard_coded/Mmakefile:
tests/invalid/Mmakefile:
    Enable the new test cases.

tests/invalid/bigtest.err_exp:
tests/invalid/bug197.err_exp:
tests/invalid/bug278.err_exp:
tests/invalid/errors2.err_exp:
tests/invalid/invalid_binary_literal.err_exp:
tests/invalid/invalid_float_literal.err_exp:
tests/invalid/invalid_hex_literal.err_exp:
tests/invalid/invalid_main.err_exp:
tests/invalid/invalid_octal_literal.err_exp:
tests/invalid/multimode_dcg.err_exp:
tests/invalid/multisoln_func.err_exp:
tests/invalid/null_char.err_exp:
tests/invalid/state_vars_test3.err_exp:
tests/invalid/try_detism.err_exp2:
tests/invalid/typeclass_test_5.err_exp:
tests/invalid/typeclass_test_8.err_exp:
tests/invalid/unsatisfiable_constraint.err_exp:
tests/invalid_purity/impure_func_t3.err_exp:
    Update these files to expect error messages in the new order.

samples/diff/*.m:
    Fix comments, mostly by moving them to where our programming style
    wants them.
2019-01-03 08:57:20 +11:00
..

This is now looking a LOT more like the standard "diff" utility.  There
are a few features missing (e.g. we can't do directory diffs), but apart
from that, it seems to work.

The major changes in this version are:

	- We now accept command-line options.  In particular, we
	  recognise all options that are accepted by GNU diff,
	  though some of them result in error reports and a few
	  which have do nothing to do with the output format or
	  semantics, but are merely for efficiency, are accepted
	  and ignored.

	- We support different output formats, in particular all
	  of the output formats supported by GNU diff. There are
	  a number of modifiers to the output formats (for example,
	  --show-function-line) which we don't yet support.

	- We have a new diff algorithm, based on the one by Eugene
	  Myers.  See myers.m for details.

	- Just about everything has been modified to support the
	  above changes.

	- Lots of cleanups, lots more documentation.

Examine the file TODO to see what's still missing.

Andrew Bromage  13 September 1998

===========================================================================

The version which appears here is a re-hacked version of Marnix Klooster's
hacked version of my original.  Special thanks to him for making my code
a lot more maintainable than it originally was.  :-)

The changes from the previous version:

	- Bug fix for a problem which was causing it to bomb out if
	  the two files were identical.

	- Changed indenting so it more closely matches the Mercury
	  compiler coding standard.

	- Update to use unique arrays (now called array.m).

	- Various minor documentation tweaks.

Oh, and it still runs in nowhere near the speed of GNU diff.

Andrew Bromage  28 Jul 1997

===========================================================================

The Mercury modules in this directory have been derived from the
'diff' sample distributed with Mercury 0.6.  That sample carries the
following copyright information, description and to-do list (in
diff.m):


%-----------------------------------------------------------------------------%
% Copyright (C) 1995 The University of Melbourne.
% This file may only be copied under the terms of the GNU General
% Public License - see the file COPYING in the Mercury distribution.
%-----------------------------------------------------------------------------%

% File: diff.m
% Main author: bromage

% Something very similar to the standard diff utility.  Sort of.  :-)

% On the still-to-do list:
%	- Add command-line options.  Probably:
%		--ignore-all-space
%		--ignore-blank-lines
%		--ignore-case
%		--rcs
%	  What others are easy and don't break up the code?


The major changes I made were

* Moved code for manipulating and displaying diffs to a separate
  module called diffs.m (and changed their calls in diff.m).  The type
  'lcss,' needed both by the rest of lcss.m and by diffs.m, was moved
  to a new module lcsstype.m.

* Made lcss.m independent of files, and allowed it to process any kind
  of list by adding polymorphism.  (The file processing calls have
  been moved to diff.m.)

* Added type synonyms 'pos' and 'segment' in diffs.m to clarify the
  types.  Renamed 'single_diff' to 'edit'.

* Added end-of-file match to the generated lcss, thereby allowing the
  to_diff predicate to be simplified considerably.

* Numbered lists from 0 internally in the lcss-algorithm.  This made
  to_diff simpler still, but also forced changes in the diff-printing
  part.

* Removed the swapping in find_lcss, because it doesn't seem to help.

* The array(string) representing a file in file.m was also renumbered
  to begin with 0.

* Added and corrected comments.

Have fun,

 <><

Marnix
--
Marnix Klooster
marnix@worldonline.nl