Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MPR#7574: hightlight differences in type error messages #1481

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
57 changes: 33 additions & 24 deletions .depend
Expand Up @@ -186,6 +186,11 @@ typing/datarepr.cmx : typing/types.cmx typing/path.cmx parsing/location.cmx \
typing/ident.cmx typing/btype.cmx parsing/asttypes.cmi \
typing/datarepr.cmi
typing/datarepr.cmi : typing/types.cmi typing/path.cmi typing/ident.cmi
typing/difftree.cmo : typing/outcometree.cmi utils/misc.cmi \
utils/clflags.cmi parsing/asttypes.cmi typing/difftree.cmi
typing/difftree.cmx : typing/outcometree.cmx utils/misc.cmx \
utils/clflags.cmx parsing/asttypes.cmi typing/difftree.cmi
typing/difftree.cmi : typing/outcometree.cmi
typing/env.cmo : utils/warnings.cmi typing/types.cmi utils/tbl.cmi \
typing/subst.cmi typing/predef.cmi typing/path.cmi utils/misc.cmi \
parsing/longident.cmi parsing/location.cmi typing/ident.cmi \
Expand Down Expand Up @@ -230,15 +235,15 @@ typing/includecore.cmi : typing/types.cmi typing/typedtree.cmi \
parsing/location.cmi typing/ident.cmi typing/env.cmi
typing/includemod.cmo : typing/types.cmi typing/typedtree.cmi utils/tbl.cmi \
typing/subst.cmi typing/printtyp.cmi typing/primitive.cmi typing/path.cmi \
typing/mtype.cmi utils/misc.cmi parsing/location.cmi \
typing/oprint.cmi typing/mtype.cmi utils/misc.cmi parsing/location.cmi \
typing/includecore.cmi typing/includeclass.cmi typing/ident.cmi \
typing/env.cmi typing/ctype.cmi typing/cmt_format.cmi utils/clflags.cmi \
typing/env.cmi typing/difftree.cmi typing/ctype.cmi typing/cmt_format.cmi \
parsing/builtin_attributes.cmi typing/btype.cmi typing/includemod.cmi
typing/includemod.cmx : typing/types.cmx typing/typedtree.cmx utils/tbl.cmx \
typing/subst.cmx typing/printtyp.cmx typing/primitive.cmx typing/path.cmx \
typing/mtype.cmx utils/misc.cmx parsing/location.cmx \
typing/oprint.cmx typing/mtype.cmx utils/misc.cmx parsing/location.cmx \
typing/includecore.cmx typing/includeclass.cmx typing/ident.cmx \
typing/env.cmx typing/ctype.cmx typing/cmt_format.cmx utils/clflags.cmx \
typing/env.cmx typing/difftree.cmx typing/ctype.cmx typing/cmt_format.cmx \
parsing/builtin_attributes.cmx typing/btype.cmx typing/includemod.cmi
typing/includemod.cmi : typing/types.cmi typing/typedtree.cmi \
typing/path.cmi parsing/location.cmi typing/includecore.cmi \
Expand All @@ -255,9 +260,11 @@ typing/mtype.cmi : typing/types.cmi typing/path.cmi typing/ident.cmi \
typing/env.cmi
typing/oprint.cmo : typing/outcometree.cmi parsing/asttypes.cmi \
typing/oprint.cmi
typing/oprint.cmx : typing/outcometree.cmi parsing/asttypes.cmi \
typing/oprint.cmx : typing/outcometree.cmx parsing/asttypes.cmi \
typing/oprint.cmi
typing/oprint.cmi : typing/outcometree.cmi
typing/outcometree.cmo : parsing/asttypes.cmi typing/outcometree.cmi
typing/outcometree.cmx : parsing/asttypes.cmi typing/outcometree.cmi
typing/outcometree.cmi : parsing/asttypes.cmi
typing/parmatch.cmo : utils/warnings.cmi typing/untypeast.cmi \
typing/types.cmi typing/typedtreeIter.cmi typing/typedtree.cmi \
Expand All @@ -274,8 +281,8 @@ typing/parmatch.cmx : utils/warnings.cmx typing/untypeast.cmx \
utils/config.cmx typing/btype.cmx parsing/asttypes.cmi \
parsing/ast_helper.cmx typing/parmatch.cmi
typing/parmatch.cmi : typing/types.cmi typing/typedtree.cmi \
parsing/parsetree.cmi parsing/longident.cmi parsing/location.cmi \
typing/env.cmi parsing/asttypes.cmi
parsing/parsetree.cmi parsing/location.cmi typing/env.cmi \
parsing/asttypes.cmi
typing/path.cmo : typing/ident.cmi typing/path.cmi
typing/path.cmx : typing/ident.cmx typing/path.cmi
typing/path.cmi : typing/ident.cmi
Expand All @@ -289,7 +296,7 @@ typing/predef.cmi : typing/types.cmi typing/path.cmi typing/ident.cmi
typing/primitive.cmo : parsing/parsetree.cmi typing/outcometree.cmi \
utils/misc.cmi parsing/location.cmi parsing/attr_helper.cmi \
typing/primitive.cmi
typing/primitive.cmx : parsing/parsetree.cmi typing/outcometree.cmi \
typing/primitive.cmx : parsing/parsetree.cmi typing/outcometree.cmx \
utils/misc.cmx parsing/location.cmx parsing/attr_helper.cmx \
typing/primitive.cmi
typing/primitive.cmi : parsing/parsetree.cmi typing/outcometree.cmi \
Expand All @@ -303,14 +310,14 @@ typing/printtyp.cmo : typing/types.cmi typing/primitive.cmi \
typing/predef.cmi typing/path.cmi parsing/parsetree.cmi \
typing/outcometree.cmi typing/oprint.cmi utils/misc.cmi \
parsing/longident.cmi parsing/location.cmi typing/ident.cmi \
typing/env.cmi typing/ctype.cmi utils/clflags.cmi \
typing/env.cmi typing/difftree.cmi typing/ctype.cmi utils/clflags.cmi \
parsing/builtin_attributes.cmi typing/btype.cmi parsing/asttypes.cmi \
typing/printtyp.cmi
typing/printtyp.cmx : typing/types.cmx typing/primitive.cmx \
typing/predef.cmx typing/path.cmx parsing/parsetree.cmi \
typing/outcometree.cmi typing/oprint.cmx utils/misc.cmx \
typing/outcometree.cmx typing/oprint.cmx utils/misc.cmx \
parsing/longident.cmx parsing/location.cmx typing/ident.cmx \
typing/env.cmx typing/ctype.cmx utils/clflags.cmx \
typing/env.cmx typing/difftree.cmx typing/ctype.cmx utils/clflags.cmx \
parsing/builtin_attributes.cmx typing/btype.cmx parsing/asttypes.cmi \
typing/printtyp.cmi
typing/printtyp.cmi : typing/types.cmi typing/path.cmi \
Expand Down Expand Up @@ -370,21 +377,23 @@ typing/typecore.cmo : utils/warnings.cmi typing/typetexp.cmi \
typing/typedecl.cmi typing/subst.cmi typing/stypes.cmi \
typing/printtyp.cmi typing/printpat.cmi typing/primitive.cmi \
typing/predef.cmi typing/path.cmi parsing/parsetree.cmi \
typing/parmatch.cmi typing/oprint.cmi utils/misc.cmi \
parsing/longident.cmi parsing/location.cmi typing/ident.cmi \
typing/env.cmi typing/ctype.cmi typing/cmt_format.cmi utils/clflags.cmi \
parsing/builtin_attributes.cmi typing/btype.cmi parsing/asttypes.cmi \
parsing/ast_helper.cmi typing/annot.cmi typing/typecore.cmi
typing/parmatch.cmi typing/outcometree.cmi typing/oprint.cmi \
utils/misc.cmi parsing/longident.cmi parsing/location.cmi \
typing/ident.cmi typing/env.cmi typing/ctype.cmi utils/config.cmi \
typing/cmt_format.cmi utils/clflags.cmi parsing/builtin_attributes.cmi \
typing/btype.cmi parsing/asttypes.cmi parsing/ast_helper.cmi \
typing/annot.cmi typing/typecore.cmi
typing/typecore.cmx : utils/warnings.cmx typing/typetexp.cmx \
typing/types.cmx typing/typeopt.cmx typing/typedtree.cmx \
typing/typedecl.cmx typing/subst.cmx typing/stypes.cmx \
typing/printtyp.cmx typing/printpat.cmx typing/primitive.cmx \
typing/predef.cmx typing/path.cmx parsing/parsetree.cmi \
typing/parmatch.cmx typing/oprint.cmx utils/misc.cmx \
parsing/longident.cmx parsing/location.cmx typing/ident.cmx \
typing/env.cmx typing/ctype.cmx typing/cmt_format.cmx utils/clflags.cmx \
parsing/builtin_attributes.cmx typing/btype.cmx parsing/asttypes.cmi \
parsing/ast_helper.cmx typing/annot.cmi typing/typecore.cmi
typing/parmatch.cmx typing/outcometree.cmx typing/oprint.cmx \
utils/misc.cmx parsing/longident.cmx parsing/location.cmx \
typing/ident.cmx typing/env.cmx typing/ctype.cmx utils/config.cmx \
typing/cmt_format.cmx utils/clflags.cmx parsing/builtin_attributes.cmx \
typing/btype.cmx parsing/asttypes.cmi parsing/ast_helper.cmx \
typing/annot.cmi typing/typecore.cmi
typing/typecore.cmi : typing/types.cmi typing/typedtree.cmi typing/path.cmi \
parsing/parsetree.cmi parsing/longident.cmi parsing/location.cmi \
typing/ident.cmi typing/env.cmi parsing/asttypes.cmi typing/annot.cmi
Expand Down Expand Up @@ -2176,7 +2185,7 @@ toplevel/genprintval.cmo : typing/types.cmi typing/printtyp.cmi \
typing/env.cmi typing/datarepr.cmi typing/ctype.cmi typing/btype.cmi \
toplevel/genprintval.cmi
toplevel/genprintval.cmx : typing/types.cmx typing/printtyp.cmx \
typing/predef.cmx typing/path.cmx typing/outcometree.cmi \
typing/predef.cmx typing/path.cmx typing/outcometree.cmx \
typing/oprint.cmx utils/misc.cmx parsing/longident.cmx typing/ident.cmx \
typing/env.cmx typing/datarepr.cmx typing/ctype.cmx typing/btype.cmx \
toplevel/genprintval.cmi
Expand Down Expand Up @@ -2214,7 +2223,7 @@ toplevel/opttoploop.cmx : utils/warnings.cmx typing/types.cmx \
typing/printtyped.cmx typing/printtyp.cmx bytecomp/printlambda.cmx \
parsing/printast.cmx typing/predef.cmx parsing/pprintast.cmx \
driver/pparse.cmx typing/path.cmx parsing/parsetree.cmi parsing/parse.cmx \
typing/outcometree.cmi typing/oprint.cmx utils/misc.cmx \
typing/outcometree.cmx typing/oprint.cmx utils/misc.cmx \
middle_end/middle_end.cmx parsing/longident.cmx parsing/location.cmx \
parsing/lexer.cmx bytecomp/lambda.cmx typing/includemod.cmx \
asmcomp/import_approx.cmx typing/ident.cmx toplevel/genprintval.cmx \
Expand Down Expand Up @@ -2278,7 +2287,7 @@ toplevel/toploop.cmx : utils/warnings.cmx typing/typetexp.cmx \
bytecomp/simplif.cmx typing/printtyped.cmx typing/printtyp.cmx \
bytecomp/printlambda.cmx bytecomp/printinstr.cmx parsing/printast.cmx \
typing/predef.cmx parsing/pprintast.cmx driver/pparse.cmx typing/path.cmx \
parsing/parsetree.cmi parsing/parse.cmx typing/outcometree.cmi \
parsing/parsetree.cmi parsing/parse.cmx typing/outcometree.cmx \
typing/oprint.cmx utils/misc.cmx bytecomp/meta.cmx parsing/longident.cmx \
parsing/location.cmx parsing/lexer.cmx typing/includemod.cmx \
typing/ident.cmx toplevel/genprintval.cmx typing/env.cmx \
Expand Down
4 changes: 4 additions & 0 deletions Changes
Expand Up @@ -38,6 +38,10 @@ Working version

### Compiler user-interface and warnings:

- MPR#7574: highlight differences in type error messages and
collapse types larger than an arbitrary limit
(Florian Angeletti)

- GPR#1166: In OCAMLPARAM, an alternative separator can be specified as
first character (instead of comma) in the set ":|; ,"
(Fabrice Le Fessant)
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -100,7 +100,7 @@ PARSING=parsing/location.cmo parsing/longident.cmo \

TYPING=typing/ident.cmo typing/path.cmo \
typing/primitive.cmo typing/types.cmo \
typing/btype.cmo typing/oprint.cmo \
typing/btype.cmo typing/outcometree.cmo typing/difftree.cmo typing/oprint.cmo \
typing/subst.cmo typing/predef.cmo \
typing/datarepr.cmo typing/cmi_format.cmo typing/env.cmo \
typing/typedtree.cmo typing/printtyped.cmo typing/ctype.cmo \
Expand Down
2 changes: 1 addition & 1 deletion debugger/Makefile
Expand Up @@ -49,7 +49,7 @@ OTHEROBJS=\
../typing/btype.cmo ../typing/primitive.cmo ../typing/typedtree.cmo \
../typing/subst.cmo ../typing/predef.cmo \
../typing/datarepr.cmo ../typing/cmi_format.cmo ../typing/env.cmo \
../typing/oprint.cmo \
../typing/outcometree.cmo ../typing/difftree.cmo ../typing/oprint.cmo \
../typing/ctype.cmo ../typing/printtyp.cmo ../typing/mtype.cmo \
../typing/envaux.cmo \
../bytecomp/runtimedef.cmo ../bytecomp/bytesections.cmo \
Expand Down
4 changes: 2 additions & 2 deletions debugger/printval.ml
Expand Up @@ -85,13 +85,13 @@ let max_printer_steps = ref 300

let print_exception ppf obj =
let t = Printer.outval_of_untyped_exception obj in
!Oprint.out_value ppf t
!Oprint.out_value ppf (Outcometree.Decorate.value t)

let print_value max_depth env obj (ppf : Format.formatter) ty =
let t =
Printer.outval_of_value !max_printer_steps max_depth
check_depth env obj ty in
!Oprint.out_value ppf t
!Oprint.out_value ppf (Outcometree.Decorate.value t)

let print_named_value max_depth exp env obj ppf ty =
let print_value_name ppf = function
Expand Down
2 changes: 2 additions & 0 deletions driver/main.ml
Expand Up @@ -43,6 +43,7 @@ module Options = Main_args.Make_bytecomp_options (struct
let _no_check_prims = set no_check_prims
let _dllib s = defer (ProcessDLLs (Misc.rev_split_words s))
let _dllpath s = dllpaths := !dllpaths @ [s]
let _error_size n = error_size := n
let _for_pack s = for_package := Some s
let _g = set debug
let _i () = print_types := true; compile_only := true
Expand Down Expand Up @@ -108,6 +109,7 @@ module Options = Main_args.Make_bytecomp_options (struct
| None -> ()
| Some setting -> color := Some setting
end
let _diff_markers = set diff_markers
let _where = print_standard_library
let _verbose = set verbose
let _nopervasives = set nopervasives
Expand Down
20 changes: 20 additions & 0 deletions driver/main_args.ml
Expand Up @@ -77,6 +77,12 @@ let mk_dllpath f =
"<dir> Add <dir> to the run-time search path for shared libraries"
;;

let mk_errorsize i =
"-error-size", Arg.Int i,
"<size> Increase the size of error messages to <size> (in arbitrary units),\
\ the default size is 12."
;;

let mk_dtypes f =
"-dtypes", Arg.Unit f, " (deprecated) same as -annot"
;;
Expand Down Expand Up @@ -589,6 +595,10 @@ let mk_color f =
\ not empty or \"dumb\", and that isatty(stderr) holds."
;;

let mk_diffmarkers f =
"-diff-markers", Arg.Unit f,
" Emphasize difference with a prefix marker in type errors."

let mk_where f =
"-where", Arg.Unit f, " Print location of standard library and exit"
;;
Expand Down Expand Up @@ -787,6 +797,8 @@ module type Common_options = sig
val _noassert : unit -> unit
val _nolabels : unit -> unit
val _nostdlib : unit -> unit
val _diff_markers: unit -> unit
val _error_size: int -> unit
val _open : string -> unit
val _ppx : string -> unit
val _principal : unit -> unit
Expand Down Expand Up @@ -1012,9 +1024,11 @@ struct
mk_compat_32 F._compat_32;
mk_config F._config;
mk_custom F._custom;
mk_diffmarkers F._diff_markers;
mk_dllib F._dllib;
mk_dllpath F._dllpath;
mk_dtypes F._annot;
mk_errorsize F._error_size;
mk_for_pack_byt F._for_pack;
mk_g_byt F._g;
mk_i F._i;
Expand Down Expand Up @@ -1114,6 +1128,8 @@ struct
mk_nopromptcont F._nopromptcont;
mk_nostdlib F._nostdlib;
mk_open F._open;
mk_diffmarkers F._diff_markers;
mk_errorsize F._error_size;
mk_ppx F._ppx;
mk_principal F._principal;
mk_no_principal F._no_principal;
Expand Down Expand Up @@ -1171,6 +1187,8 @@ struct
mk_compact F._compact;
mk_config F._config;
mk_dtypes F._annot;
mk_diffmarkers F._diff_markers;
mk_errorsize F._error_size;
mk_for_pack_opt F._for_pack;
mk_g_opt F._g;
mk_i F._i;
Expand Down Expand Up @@ -1327,6 +1345,8 @@ module Make_opttop_options (F : Opttop_options) = struct
mk_o2 F._o2;
mk_o3 F._o3;
mk_open F._open;
mk_diffmarkers F._diff_markers;
mk_errorsize F._error_size;
mk_ppx F._ppx;
mk_principal F._principal;
mk_no_principal F._no_principal;
Expand Down
2 changes: 2 additions & 0 deletions driver/main_args.mli
Expand Up @@ -27,6 +27,8 @@ module type Common_options = sig
val _noassert : unit -> unit
val _nolabels : unit -> unit
val _nostdlib : unit -> unit
val _diff_markers: unit -> unit
val _error_size: int -> unit
val _open : string -> unit
val _ppx : string -> unit
val _principal : unit -> unit
Expand Down
2 changes: 2 additions & 0 deletions driver/optmain.ml
Expand Up @@ -58,6 +58,7 @@ module Options = Main_args.Make_optcomp_options (struct
let _clambda_checks () = clambda_checks := true
let _compact = clear optimize_for_speed
let _config () = show_config ()
let _error_size n = error_size := n
let _for_pack s = for_package := Some s
let _g = set debug
let _i () = print_types := true; compile_only := true
Expand Down Expand Up @@ -192,6 +193,7 @@ module Options = Main_args.Make_optcomp_options (struct
| None -> ()
| Some setting -> color := Some setting
end
let _diff_markers = set diff_markers
let _where () = print_standard_library ()

let _nopervasives = set nopervasives
Expand Down
11 changes: 11 additions & 0 deletions man/ocaml.m
Expand Up @@ -70,6 +70,17 @@
.B \-absname
Show absolute filenames in error messages.
.TP
.B \-diff-markers
Use textual markers to highlight differences in error messages
and do not rely only on color.
.TP
.BI \-error-size \ size
Set the optimal error size for type error messages in arbitrary units.
The default size is 12, a typical range for this size would be between
3 and 30.
Types larger than this error size will be elided in order to fit this
limit.
.TP
.BI \-I \ directory
Add the given directory to the list of directories searched for
source and compiled files. By default, the current directory is
Expand Down
11 changes: 11 additions & 0 deletions man/ocamlc.m
Expand Up @@ -331,6 +331,10 @@ use heuristics to enable colors only if the output supports them (an
.BR ocamlrun (1)
at program start-up time.
.TP
.B \-diff-markers
Use textual markers to highlight differences in error messages
and do not rely only on color.
.TP
.BI \-dllpath \ dir
Adds the directory
.I dir
Expand All @@ -348,6 +352,13 @@ standard search path (the one corresponding to the
.BR ocamlrun (1)
can find it and use it.
.TP
.BI \-error-size \ size
Set the optimal error size for type error messages in arbitrary units.
The default size is 12, a typical range for this size would be between
3 and 30.
Types larger than this error size will be elided in order to fit
this limit.
.TP
.BI \-for\-pack \ module\-path
Generate an object file (.cmo file) that can later be included
as a sub-module (with the given access path) of a compilation unit
Expand Down
11 changes: 11 additions & 0 deletions man/ocamlopt.m
Expand Up @@ -255,6 +255,17 @@ use heuristics to enable colors only if the output supports them (an
.BI \-depend\ ocamldep-args
Compute dependencies, as ocamldep would do.
.TP
.B \-diff-markers
Use textual markers to highlight differences in error messages
and do not rely only on color.
.TP
.BI \-error-size \ size
Set the optimal error size for type error messages in arbitrary units.
The default size is 12, a typical range for this size would be between
3 and 30.
Types larger than this error size will be elided in order to fit
this limit.
.TP
.BI \-for\-pack \ module\-path
Generate an object file (.cmx and .o files) that can later be included
as a sub-module (with the given access path) of a compilation unit
Expand Down
11 changes: 11 additions & 0 deletions manual/manual/cmds/unified-options.etex
Expand Up @@ -183,6 +183,11 @@ Compute dependencies, as the "ocamldep" command would do. The remaining
arguments are interpreted as if they were given to the "ocamldep" command.
}%notop


\item["-diff-marker" \var{size}]
Use textual markers to highlight differences in error messages
and do not rely only on color.

\comp{
\item["-dllib" "-l"\var{libname}]
Arrange for the C shared library "dll"\var{libname}".so"
Expand All @@ -199,6 +204,12 @@ executable file, where "ocamlrun" can find it and use it as
described in section~\ref{s-ocamlrun-dllpath}.
}%comp

\item["-error-size" \var{size}]
Set the optimal error size for type error messages in arbitrary units.
The default size is 12, a typical range for this size would be between 3
and 30.
Types larger than this error size will be elided in order to fit this limit.

\notop{%
\item["-for-pack" \var{module-path}]
Generate an object file (\qcmo\nat{ and ".o"/".obj" files})
Expand Down
2 changes: 2 additions & 0 deletions ocamldoc/odoc_args.ml
Expand Up @@ -213,6 +213,8 @@ module Options = Main_args.Make_ocamldoc_options(struct
let _noassert = set Clflags.noassert
let _nolabels = set Clflags.classic
let _nostdlib = set Clflags.no_std_include
let _diff_markers = set Clflags.diff_markers
let _error_size n = Clflags.error_size := n
let _open s = Clflags.open_modules := s :: !Clflags.open_modules
let _pp s = Clflags.preprocessor := Some s
let _ppx s = Clflags.all_ppx := s :: !Clflags.all_ppx
Expand Down