[m-rev.] diff: better type mismatch error message

Zoltan Somogyi zs at csse.unimelb.edu.au
Thu Dec 7 11:51:28 AEDT 2006


compiler/typecheck_errors.m:
	Generate better error messages for some type errors by ignoring
	irrelevant differences between two descriptions of a type mismatch
	(e.g. a difference in the number of variables in a tvarset).

The motivating example was this error message:

stack_layout.m:955: In clause for predicate `construct_internal_layout'/7:
stack_layout.m:955:   in unification of variable `UserData'
stack_layout.m:955:   and term
stack_layout.m:955:   `user_event_data(UserEventNumber, NumAttributes,
UserLocnsRval, UserAttrVarNums)':
stack_layout.m:955:   type error in argument(s) of functor `user_event_data/4'.
stack_layout.m:955:   variable `UserData' has type
stack_layout.m:955:   `((ll_backend.layout).user_event_data)',
stack_layout.m:955:   functor `user_event_data/4' has type
stack_layout.m:955:   `user_event_data(int, int, ((ll_backend.llds).rval),
stack_layout.m:955:   (list.list((maybe.maybe(int))))):
stack_layout.m:955:   ((ll_backend.layout).user_event_data)',
stack_layout.m:955:   variable `UserEventNumber' has type `int',
stack_layout.m:955:   variable `NumAttributes' has type `int',
stack_layout.m:955:   variable `UserLocnsRval' has type
stack_layout.m:955:   `((ll_backend.llds).rval)',
stack_layout.m:955:   variable `UserAttrVarNums' has type `(list.list(int))'.

After this diff, the same buggy input now gets this more focused message:

stack_layout.m:955: In clause for predicate `construct_internal_layout'/7:
stack_layout.m:955:   in unification of variable `UserData'
stack_layout.m:955:   and term
stack_layout.m:955:   `user_event_data(UserEventNumber, NumAttributes,
UserLocnsRval, UserAttrVarNums)':
stack_layout.m:955:   type error in argument(s) of functor `user_event_data/4'.
stack_layout.m:955:   Argument 4 (UserAttrVarNums) has type `(list.list(int))',
stack_layout.m:955:   expected type was `(list.list((maybe.maybe(int))))'.

Zoltan.

cvs diff: Diffing .
cvs diff: Diffing analysis
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/doc
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing boehm_gc/libatomic_ops-1.2
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/doc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/gcc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/hpc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/ibmc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/icc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/msftc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/sunc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/tests
cvs diff: Diffing boehm_gc/tests
cvs diff: Diffing boehm_gc/windows-untested
cvs diff: Diffing boehm_gc/windows-untested/vc60
cvs diff: Diffing boehm_gc/windows-untested/vc70
cvs diff: Diffing boehm_gc/windows-untested/vc71
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
Index: compiler/typecheck_errors.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/typecheck_errors.m,v
retrieving revision 1.34
diff -u -b -r1.34 typecheck_errors.m
--- compiler/typecheck_errors.m	28 Nov 2006 06:17:12 -0000	1.34
+++ compiler/typecheck_errors.m	6 Dec 2006 11:40:29 -0000
@@ -699,11 +699,8 @@
 
 :- type type_mismatch
     --->    type_mismatch(
-                mer_type,   % actual type of that variable
-                mer_type,   % expected type of that variable
-                tvarset,    % the type vars in the expected
-                            % and expected types
-                head_type_params % existentially quantified type vars
+                actual_type_desc    :: list(format_component),
+                expected_type_desc  :: list(format_component)
             ).
 
 :- pred find_mismatched_args(assoc_list(prog_var, mer_type)::in,
@@ -712,32 +709,26 @@
 
 find_mismatched_args([], _, _, [], [], []).
 find_mismatched_args([Arg - ExpType | ArgExpTypes], TypeAssignSet, ArgNum0,
-        SimpleMismatches, ComplexMismatches, AllMismatches) :-
+        !:SimpleMismatches, !:ComplexMismatches, !:AllMismatches) :-
     ArgNum1 = ArgNum0 + 1,
     find_mismatched_args(ArgExpTypes, TypeAssignSet, ArgNum1,
-        SimpleMismatchesTail, ComplexMismatchesTail,
-        AllMismatchesTail),
+        !:SimpleMismatches, !:ComplexMismatches, !:AllMismatches),
     get_type_stuff(TypeAssignSet, Arg, TypeStuffList),
     list.filter_map(substitute_types_check_match(ExpType), TypeStuffList,
         TypeMismatches0),
     list.sort_and_remove_dups(TypeMismatches0, TypeMismatches),
     (
-        TypeMismatches = [],
-        SimpleMismatches = SimpleMismatchesTail,
-        ComplexMismatches = ComplexMismatchesTail,
-        AllMismatches = AllMismatchesTail
+        TypeMismatches = []
     ;
         TypeMismatches = [_],
         Mismatch = mismatch_info(ArgNum0, Arg, TypeMismatches),
-        SimpleMismatches = [Mismatch | SimpleMismatchesTail],
-        ComplexMismatches = ComplexMismatchesTail,
-        AllMismatches = [Mismatch | AllMismatchesTail]
+        !:SimpleMismatches = [Mismatch | !.SimpleMismatches],
+        !:AllMismatches = [Mismatch | !.AllMismatches]
     ;
         TypeMismatches = [_, _ | _],
         Mismatch = mismatch_info(ArgNum0, Arg, TypeMismatches),
-        SimpleMismatches = SimpleMismatchesTail,
-        ComplexMismatches = [Mismatch | ComplexMismatchesTail],
-        AllMismatches = [Mismatch | AllMismatchesTail]
+        !:ComplexMismatches = [Mismatch | !.ComplexMismatches],
+        !:AllMismatches = [Mismatch | !.AllMismatches]
     ).
 
 :- pred substitute_types_check_match(mer_type::in, type_stuff::in,
@@ -749,19 +740,20 @@
     apply_rec_subst_to_type(TypeBindings, ExpType, FullExpType),
     (
         (
-            % There is no mismatch if the actual type of the
-            % argument is the same as the expected type.
+            % There is no mismatch if the actual type of the argument
+            % is the same as the expected type.
             identical_types(FullArgType, FullExpType)
         ;
-            % There is no mismatch if the actual type of the
-            % argument has no constraints on it.
+            % There is no mismatch if the actual type of the argument
+            % has no constraints on it.
             FullArgType = defined_type(unqualified("<any>"), [], _)
         )
     ->
         fail
     ;
-        TypeMismatch = type_mismatch(FullArgType, FullExpType,
-            TVarSet, HeadTypeParams)
+        ActualPieces = type_to_pieces(FullArgType, TVarSet, HeadTypeParams),
+        ExpectedPieces = type_to_pieces(FullExpType, TVarSet, HeadTypeParams),
+        TypeMismatch = type_mismatch(ActualPieces, ExpectedPieces)
     ).
 
 :- func mismatched_args_to_pieces(list(mismatch_info), bool, prog_varset,
@@ -772,7 +764,7 @@
         = Pieces :-
     Mismatch = mismatch_info(ArgNum, Var, TypeMismatches),
     ( TypeMismatches = [TypeMismatch] ->
-        TypeMismatch = type_mismatch(ActType, ExpType, TVarSet, HeadTypeParams)
+        TypeMismatch = type_mismatch(ActTypePieces, ExpTypePieces)
     ;
         unexpected(this_file,
             "report_mismatched_args: more than one type mismatch")
@@ -812,10 +804,10 @@
         Pieces2 = []
     ),
     Pieces3 = [words("has type"), prefix("`")] ++
-        type_to_pieces(ActType, TVarSet, HeadTypeParams) ++
+        ActTypePieces ++
         [suffix("'"), suffix(","), nl] ++
         [words("expected type was"), prefix("`")] ++
-        type_to_pieces(ExpType, TVarSet, HeadTypeParams) ++
+        ExpTypePieces ++
         [suffix("'")],
     (
         Mismatches = [],
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
cvs diff: Diffing debian/patches
cvs diff: Diffing deep_profiler
cvs diff: Diffing deep_profiler/notes
cvs diff: Diffing doc
cvs diff: Diffing extras
cvs diff: Diffing extras/base64
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/concurrency
cvs diff: Diffing extras/curs
cvs diff: Diffing extras/curs/samples
cvs diff: Diffing extras/curses
cvs diff: Diffing extras/curses/sample
cvs diff: Diffing extras/dynamic_linking
cvs diff: Diffing extras/error
cvs diff: Diffing extras/fixed
cvs diff: Diffing extras/gator
cvs diff: Diffing extras/gator/generations
cvs diff: Diffing extras/gator/generations/1
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/easyx
cvs diff: Diffing extras/graphics/easyx/samples
cvs diff: Diffing extras/graphics/mercury_glut
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/gears
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/lazy_evaluation
cvs diff: Diffing extras/lex
cvs diff: Diffing extras/lex/samples
cvs diff: Diffing extras/lex/tests
cvs diff: Diffing extras/log4m
cvs diff: Diffing extras/logged_output
cvs diff: Diffing extras/moose
cvs diff: Diffing extras/moose/samples
cvs diff: Diffing extras/moose/tests
cvs diff: Diffing extras/mopenssl
cvs diff: Diffing extras/morphine
cvs diff: Diffing extras/morphine/non-regression-tests
cvs diff: Diffing extras/morphine/scripts
cvs diff: Diffing extras/morphine/source
cvs diff: Diffing extras/net
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/posix
cvs diff: Diffing extras/quickcheck
cvs diff: Diffing extras/quickcheck/tutes
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/solver_types
cvs diff: Diffing extras/solver_types/library
cvs diff: Diffing extras/stream
cvs diff: Diffing extras/stream/tests
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing extras/windows_installer_generator
cvs diff: Diffing extras/windows_installer_generator/sample
cvs diff: Diffing extras/windows_installer_generator/sample/images
cvs diff: Diffing extras/xml
cvs diff: Diffing extras/xml/samples
cvs diff: Diffing extras/xml_stylesheets
cvs diff: Diffing java
cvs diff: Diffing java/runtime
cvs diff: Diffing library
cvs diff: Diffing mdbcomp
cvs diff: Diffing profiler
cvs diff: Diffing robdd
cvs diff: Diffing runtime
cvs diff: Diffing runtime/GETOPT
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing samples/solutions
cvs diff: Diffing samples/tests
cvs diff: Diffing samples/tests/c_interface
cvs diff: Diffing samples/tests/c_interface/c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/tests/c_interface/mercury_calls_c
cvs diff: Diffing samples/tests/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/tests/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/tests/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/tests/diff
cvs diff: Diffing samples/tests/muz
cvs diff: Diffing samples/tests/rot13
cvs diff: Diffing samples/tests/solutions
cvs diff: Diffing samples/tests/toplevel
cvs diff: Diffing scripts
cvs diff: Diffing slice
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
cvs diff: Diffing tests/debugger/declarative
cvs diff: Diffing tests/dppd
cvs diff: Diffing tests/general
cvs diff: Diffing tests/general/accumulator
cvs diff: Diffing tests/general/string_format
cvs diff: Diffing tests/general/structure_reuse
cvs diff: Diffing tests/grade_subdirs
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/exceptions
cvs diff: Diffing tests/hard_coded/purity
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/invalid/purity
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/mmc_make
cvs diff: Diffing tests/mmc_make/lib
cvs diff: Diffing tests/par_conj
cvs diff: Diffing tests/recompilation
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/trailing
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trace
cvs diff: Diffing util
cvs diff: Diffing vim
cvs diff: Diffing vim/after
cvs diff: Diffing vim/ftplugin
cvs diff: Diffing vim/syntax
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list