···34343535exception Error of error
36363737-val report_error: Format.formatter -> error -> unit
3737+val report_error: error Format_doc.printer
+1-1
asmcomp/emitaux.ml
···459459460460let report_error ppf = function
461461 | Stack_frame_too_large n ->
462462- Format.fprintf ppf "stack frame too large (%d bytes)" n
462462+ Format_doc.fprintf ppf "stack frame too large (%d bytes)" n
463463464464let mk_env f : Emitenv.per_function_env =
465465 {
+1-1
asmcomp/emitaux.mli
···8787 | Stack_frame_too_large of int
88888989exception Error of error
9090-val report_error: Format.formatter -> error -> unit
9090+val report_error: error Format_doc.printer
91919292val mk_env : Linear.fundecl -> Emitenv.per_function_env
9393
+1-1
asmcomp/polling.ml
···1818(**************************************************************************)
19192020open Mach
2121-open Format
2121+open Format_doc
22222323module Int = Numbers.Int
2424module String = Misc.Stdlib.String
+1-1
bytecomp/bytelibrarian.ml
···121121 output_binary_int outchan pos_toc;
122122 )
123123124124-open Format
124124+open Format_doc
125125module Style = Misc.Style
126126127127let report_error ppf = function
+1-4
bytecomp/bytelibrarian.mli
···31313232exception Error of error
33333434-open Format
3535-3636-val report_error: formatter -> error -> unit
3737-3434+val report_error: error Format_doc.printer
3835val reset: unit -> unit
···28282929exception Error of error
30303131-val report_error: Format.formatter -> error -> unit
3131+val report_error: error Format_doc.printer
+1-1
bytecomp/emitcode.ml
···383839394040let report_error ppf (file, kind) =
4141- Format.fprintf ppf "Generated %s %S cannot be used on a 32-bit platform"
4141+ Format_doc.fprintf ppf "Generated %s %S cannot be used on a 32-bit platform"
4242 kind file
4343let () =
4444 Location.register_error_of_exn
+4-3
bytecomp/symtable.ml
···52525353 let description ppf = function
5454 | Glob_compunit (Compunit cu) ->
5555- Format.fprintf ppf "compilation unit %a" Style.inline_code (quote cu)
5555+ Format_doc.fprintf ppf "compilation unit %a"
5656+ Style.inline_code (quote cu)
5657 | Glob_predef (Predef_exn exn) ->
5757- Format.fprintf ppf "predefined exception %a"
5858+ Format_doc.fprintf ppf "predefined exception %a"
5859 Style.inline_code (quote exn)
59606061 let of_ident id =
···435436436437(* Error report *)
437438438438-open Format
439439+open Format_doc
439440440441let report_error ppf = function
441442 | Undefined_global global ->
+2-4
bytecomp/symtable.mli
···3737 | Glob_compunit of compunit
3838 | Glob_predef of predef
3939 val name: t -> string
4040- val description: Format.formatter -> t -> unit
4040+ val description: t Format_doc.printer
4141 val of_ident: Ident.t -> t option
4242 module Set : Set.S with type elt = t
4343 module Map : Map.S with type key = t
···90909191exception Error of error
92929393-open Format
9494-9595-val report_error: formatter -> error -> unit
9393+val report_error: error Format_doc.printer
96949795val reset: unit -> unit
···187187open Format
188188module Style = Misc.Style
189189190190+let as_inline_code pr = Format_doc.compat @@ Style.as_inline_code pr
191191+let inline_code = Format_doc.compat Style.inline_code
192192+190193let report_error ppf = function
191194 | Unbound_identifier id ->
192195 fprintf ppf "@[Unbound identifier %a@]@."
193193- Style.inline_code (Ident.name id)
196196+ inline_code (Ident.name id)
194197 | Not_initialized_yet path ->
195198 fprintf ppf
196199 "@[The module path %a is not yet initialized.@ \
197200 Please run program forward@ \
198201 until its initialization code is executed.@]@."
199199- (Style.as_inline_code Printtyp.path) path
202202+ (as_inline_code Printtyp.path) path
200203 | Unbound_long_identifier lid ->
201204 fprintf ppf "@[Unbound identifier %a@]@."
202202- (Style.as_inline_code Printtyp.longident) lid
205205+ (as_inline_code Printtyp.longident) lid
203206 | Unknown_name n ->
204207 fprintf ppf "@[Unknown value name $%i@]@." n
205208 | Tuple_index(ty, len, pos) ->
206209 fprintf ppf
207210 "@[Cannot extract field number %i from a %i-tuple of type@ %a@]@."
208208- pos len (Style.as_inline_code Printtyp.type_expr) ty
211211+ pos len (as_inline_code Printtyp.type_expr) ty
209212 | Array_index(len, pos) ->
210213 fprintf ppf
211214 "@[Cannot extract element number %i from an array of length %i@]@."
···222225 | Wrong_item_type(ty, pos) ->
223226 fprintf ppf
224227 "@[Cannot extract item number %i from a value of type@ %a@]@."
225225- pos (Style.as_inline_code Printtyp.type_expr) ty
228228+ pos (as_inline_code Printtyp.type_expr) ty
226229 | Wrong_label(ty, lbl) ->
227230 fprintf ppf
228231 "@[The record type@ %a@ has no label named %a@]@."
229229- (Style.as_inline_code Printtyp.type_expr) ty
230230- Style.inline_code lbl
232232+ (as_inline_code Printtyp.type_expr) ty
233233+ inline_code lbl
231234 | Not_a_record ty ->
232235 fprintf ppf
233236 "@[The type@ %a@ is not a record type@]@."
234234- (Style.as_inline_code Printtyp.type_expr) ty
237237+ (as_inline_code Printtyp.type_expr) ty
235238 | No_result ->
236239 fprintf ppf "@[No result available at current program event@]@."
+7-5
debugger/loadprinter.ml
···140140141141open Format
142142module Style = Misc.Style
143143+let quoted_longident =
144144+ Format_doc.compat @@ Style.as_inline_code Printtyp.longident
143145144146let report_error ppf = function
145147 | Load_failure e ->
···147149 (Dynlink.error_message e)
148150 | Unbound_identifier lid ->
149151 fprintf ppf "@[Unbound identifier %a@]@."
150150- (Style.as_inline_code Printtyp.longident) lid
152152+ quoted_longident lid
151153 | Unavailable_module(md, lid) ->
152154 fprintf ppf
153155 "@[The debugger does not contain the code for@ %a.@ \
154154- Please load an implementation of %s first.@]@."
155155- (Style.as_inline_code Printtyp.longident) lid md
156156+ Please load an implementation of %s first.@]@."
157157+ quoted_longident lid md
156158 | Wrong_type lid ->
157159 fprintf ppf "@[%a has the wrong type for a printing function.@]@."
158158- (Style.as_inline_code Printtyp.longident) lid
160160+ quoted_longident lid
159161 | No_active_printer lid ->
160162 fprintf ppf "@[%a is not currently active as a printing function.@]@."
161161- (Style.as_inline_code Printtyp.longident) lid
163163+ quoted_longident lid
···45454646exception Error of Location.t * error
47474848-open Format
4949-5050-val report_error: formatter -> error -> unit
4848+val report_error: error Format_doc.printer
51495250(* Forward declaration -- to be filled in by Translmod.transl_module *)
5351val transl_module :
+5-5
lambda/translmod.ml
···1657165716581658(* Error report *)
1659165916601660-open Format
16601660+open Format_doc
16611661module Style = Misc.Style
1662166216631663let print_cycle ppf cycle =
16641664- let print_ident ppf (x,_) = Format.pp_print_string ppf (Ident.name x) in
16641664+ let print_ident ppf (x,_) = pp_print_string ppf (Ident.name x) in
16651665 let pp_sep ppf () = fprintf ppf "@ -> " in
16661666- Format.fprintf ppf "%a%a%s"
16671667- (Format.pp_print_list ~pp_sep print_ident) cycle
16661666+ fprintf ppf "%a%a%s"
16671667+ (pp_print_list ~pp_sep print_ident) cycle
16681668 pp_sep ()
16691669 (Ident.name @@ fst @@ List.hd cycle)
16701670(* we repeat the first element to make the cycle more apparent *)
···16741674 | Unnamed -> assert false (* can't be part of a cycle. *)
16751675 | Unsafe {reason;loc;subid} ->
16761676 let print fmt =
16771677- let printer = Format.dprintf fmt
16771677+ let printer = doc_printf fmt
16781678 Style.inline_code (Ident.name id)
16791679 Style.inline_code (Ident.name subid) in
16801680 Location.mkloc printer loc in
···119119 incr num_loc_lines
120120121121(* This is used by the toplevel and the report printers below. *)
122122-let separate_new_message ppf =
122122+let separate_new_message ppf () =
123123 if not (is_first_message ()) then begin
124124- Format.pp_print_newline ppf ();
124124+ Format_doc.pp_print_newline ppf ();
125125 incr num_loc_lines
126126 end
127127···146146 pp_print_flush ppf ();
147147 pp_set_formatter_out_functions ppf out_functions
148148149149+(** {1 Printing setup }*)
150150+149151let setup_tags () =
150152 Misc.Style.setup !Clflags.color
153153+154154+module Fmt = Format_doc
151155152156(******************************************************************************)
153157(* Printing locations, e.g. 'File "foo.ml", line 3, characters 10-12' *)
···205209 if !Clflags.absname then absolute_path file else file
206210207211let print_filename ppf file =
208208- Format.pp_print_string ppf (show_filename file)
212212+ Fmt.pp_print_string ppf (show_filename file)
209213210214(* Best-effort printing of the text describing a location, of the form
211215 'File "foo.ml", line 3, characters 10-12'.
···242246 if !first then (first := false; String.capitalize_ascii s)
243247 else s in
244248 let comma () =
245245- if !first then () else Format.fprintf ppf ", " in
249249+ if !first then () else Fmt.fprintf ppf ", " in
246250247247- Format.fprintf ppf "@{<loc>";
251251+ Fmt.fprintf ppf "@{<loc>";
248252249253 if file_valid file then
250250- Format.fprintf ppf "%s \"%a\"" (capitalize "file") print_filename file;
254254+ Fmt.fprintf ppf "%s \"%a\"" (capitalize "file") print_filename file;
251255252256 (* Print "line 1" in the case of a dummy line number. This is to please the
253257 existing setup of editors that parse locations in error messages (e.g.
···256260 let startline = if line_valid startline then startline else 1 in
257261 let endline = if line_valid endline then endline else startline in
258262 begin if startline = endline then
259259- Format.fprintf ppf "%s %i" (capitalize "line") startline
263263+ Fmt.fprintf ppf "%s %i" (capitalize "line") startline
260264 else
261261- Format.fprintf ppf "%s %i-%i" (capitalize "lines") startline endline
265265+ Fmt.fprintf ppf "%s %i-%i" (capitalize "lines") startline endline
262266 end;
263267264268 if chars_valid ~startchar ~endchar then (
265269 comma ();
266266- Format.fprintf ppf "%s %i-%i" (capitalize "characters") startchar endchar
270270+ Fmt.fprintf ppf "%s %i-%i" (capitalize "characters") startchar endchar
267271 );
268272269269- Format.fprintf ppf "@}"
273273+ Fmt.fprintf ppf "@}"
270274271275(* Print a comma-separated list of locations *)
272276let print_locs ppf locs =
273273- Format.pp_print_list ~pp_sep:(fun ppf () -> Format.fprintf ppf ",@ ")
277277+ Fmt.pp_print_list ~pp_sep:(fun ppf () -> Fmt.fprintf ppf ",@ ")
274278 print_loc ppf locs
279279+280280+module Compat = struct
281281+ let print_filename = Fmt.compat print_filename
282282+ let print_loc = Fmt.compat print_loc
283283+ let print_locs = Fmt.compat print_locs
284284+ let separate_new_message = Fmt.compat separate_new_message
285285+end
275286276287(******************************************************************************)
277288(* An interval set structure; additionally, it stores user-provided information
···497508 Option.fold ~some:Int.to_string ~none:"" lnum,
498509 start_pos))
499510 in
500500- Format.fprintf ppf "@[<v>";
511511+ Fmt.fprintf ppf "@[<v>";
501512 begin match lines with
502513 | [] | [("", _, _)] -> ()
503514 | [(line, line_nb, line_start_cnum)] ->
504515 (* Single-line error *)
505505- Format.fprintf ppf "%s | %s@," line_nb line;
506506- Format.fprintf ppf "%*s " (String.length line_nb) "";
516516+ Fmt.fprintf ppf "%s | %s@," line_nb line;
517517+ Fmt.fprintf ppf "%*s " (String.length line_nb) "";
507518 (* Iterate up to [rightmost], which can be larger than the length of
508519 the line because we may point to a location after the end of the
509520 last token on the line, for instance:
···515526 for i = 0 to rightmost.pos_cnum - line_start_cnum - 1 do
516527 let pos = line_start_cnum + i in
517528 if ISet.is_start iset ~pos <> None then
518518- Format.fprintf ppf "@{<%s>" highlight_tag;
519519- if ISet.mem iset ~pos then Format.pp_print_char ppf '^'
529529+ Fmt.fprintf ppf "@{<%s>" highlight_tag;
530530+ if ISet.mem iset ~pos then Fmt.pp_print_char ppf '^'
520531 else if i < String.length line then begin
521532 (* For alignment purposes, align using a tab for each tab in the
522533 source code *)
523523- if line.[i] = '\t' then Format.pp_print_char ppf '\t'
524524- else Format.pp_print_char ppf ' '
534534+ if line.[i] = '\t' then Fmt.pp_print_char ppf '\t'
535535+ else Fmt.pp_print_char ppf ' '
525536 end;
526537 if ISet.is_end iset ~pos <> None then
527527- Format.fprintf ppf "@}"
538538+ Fmt.fprintf ppf "@}"
528539 done;
529529- Format.fprintf ppf "@}@,"
540540+ Fmt.fprintf ppf "@}@,"
530541 | _ ->
531542 (* Multi-line error *)
532532- Misc.pp_two_columns ~sep:"|" ~max_lines ppf
543543+ Fmt.pp_two_columns ~sep:"|" ~max_lines ppf
533544 @@ List.map (fun (line, line_nb, line_start_cnum) ->
534545 let line = String.mapi (fun i car ->
535546 if ISet.mem iset ~pos:(line_start_cnum + i) then car else '.'
···537548 (line_nb, line)
538549 ) lines
539550 end;
540540- Format.fprintf ppf "@]"
551551+ Fmt.fprintf ppf "@]"
541552542553543554···633644(******************************************************************************)
634645(* Reporting errors and warnings *)
635646636636-type msg = (Format.formatter -> unit) loc
647647+type msg = Fmt.t loc
637648638649let msg ?(loc = none) fmt =
639639- Format.kdprintf (fun txt -> { loc; txt }) fmt
650650+ Fmt.kdoc_printf (fun txt -> { loc; txt }) fmt
640651641652type report_kind =
642653 | Report_error
···649660 kind : report_kind;
650661 main : msg;
651662 sub : msg list;
652652- footnote: unit -> (Format.formatter -> unit) option;
663663+ footnote: Fmt.t option;
653664}
654665655666type report_printer = {
···662673 pp_main_loc : report_printer -> report ->
663674 Format.formatter -> t -> unit;
664675 pp_main_txt : report_printer -> report ->
665665- Format.formatter -> (Format.formatter -> unit) -> unit;
676676+ Format.formatter -> Fmt.t -> unit;
666677 pp_submsgs : report_printer -> report ->
667678 Format.formatter -> msg list -> unit;
668679 pp_submsg : report_printer -> report ->
···670681 pp_submsg_loc : report_printer -> report ->
671682 Format.formatter -> t -> unit;
672683 pp_submsg_txt : report_printer -> report ->
673673- Format.formatter -> (Format.formatter -> unit) -> unit;
684684+ Format.formatter -> Fmt.t -> unit;
674685}
675686676687let is_dummy_loc loc =
···726737 | Misc.Error_style.Short ->
727738 ()
728739 in
729729- Format.fprintf ppf "@[<v>%a:@ %a@]" print_loc loc highlight loc
740740+ Format.fprintf ppf "@[<v>%a:@ %a@]" Compat.print_loc loc
741741+ (Fmt.compat highlight) loc
730742 in
731731- let pp_txt ppf txt = Format.fprintf ppf "@[%t@]" txt in
743743+ let pp_txt ppf txt = Format.fprintf ppf "@[%a@]" Fmt.format txt in
732744 let pp_footnote ppf f =
733733- Option.iter (Format.fprintf ppf "@,%a" pp_txt) (f ())
745745+ Option.iter (Format.fprintf ppf "@,%a" pp_txt) f
734746 in
735747 let pp self ppf report =
736748 setup_tags ();
737737- separate_new_message ppf;
749749+ Fmt.compat separate_new_message ppf ();
738750 (* Make sure we keep [num_loc_lines] updated.
739751 The tabulation box is here to give submessage the option
740752 to be aligned with the main message box
···801813 let pp_main_loc _ _ _ _ = () in
802814 let pp_submsg_loc _ _ ppf loc =
803815 if not loc.loc_ghost then
804804- Format.fprintf ppf "%a:@ " print_loc loc in
816816+ Format.fprintf ppf "%a:@ " Compat.print_loc loc in
805817 { batch_mode_printer with pp; pp_main_loc; pp_submsg_loc }
806818807819let best_toplevel_printer () =
···829841(* Reporting errors *)
830842831843type error = report
832832-type delayed_msg = unit -> (Format.formatter -> unit) option
844844+type delayed_msg = unit -> Fmt.t option
833845834846let report_error ppf err =
835847 print_report ppf err
836848837849let mkerror loc sub footnote txt =
838838- { kind = Report_error; main = { loc; txt }; sub; footnote }
850850+ { kind = Report_error; main = { loc; txt }; sub; footnote=footnote () }
839851840852let errorf ?(loc = none) ?(sub = []) ?(footnote=Fun.const None) =
841841- Format.kdprintf (mkerror loc sub footnote)
853853+ Fmt.kdoc_printf (mkerror loc sub footnote)
842854843855let error ?(loc = none) ?(sub = []) ?(footnote=Fun.const None) msg_str =
844844- mkerror loc sub footnote (fun ppf -> Format.pp_print_string ppf msg_str)
856856+ mkerror loc sub footnote Fmt.(Core.string msg_str empty)
845857846858let error_of_printer ?(loc = none) ?(sub = []) ?(footnote=Fun.const None) pp x =
847847- mkerror loc sub footnote (fun ppf -> pp ppf x)
859859+ mkerror loc sub footnote (Fmt.doc_printf "%a" pp x)
848860849861let error_of_printer_file print x =
850862 error_of_printer ~loc:(in_file !input_name) print x
···857869 match report w with
858870 | `Inactive -> None
859871 | `Active { Warnings.id; message; is_error; sub_locs } ->
860860- let msg_of_str str = fun ppf -> Format.pp_print_string ppf str in
872872+ let msg_of_str str = Format_doc.(empty |> Core.string str) in
861873 let kind = mk is_error id in
862874 let main = { loc; txt = msg_of_str message } in
863875 let sub = List.map (fun (loc, sub_message) ->
864876 { loc; txt = msg_of_str sub_message }
865877 ) sub_locs in
866866- Some { kind; main; sub; footnote=Fun.const None }
878878+ Some { kind; main; sub; footnote=None }
867879868880869881let default_warning_reporter =
···913925module Style = Misc.Style
914926915927let auto_include_alert lib =
916916- let message = Format.asprintf "\
928928+ let message = Fmt.asprintf "\
917929 OCaml's lib directory layout changed in 5.0. The %a subdirectory has been \
918930 automatically added to the search path, but you should add %a to the \
919931 command-line to silence this alert (e.g. by adding %a to the list of \
···932944 prerr_alert none alert
933945934946let deprecated_script_alert program =
935935- let message = Format.asprintf "\
947947+ let message = Fmt.asprintf "\
936948 Running %a where the first argument is an implicit basename with no \
937949 extension (e.g. %a) is deprecated. Either rename the script \
938950 (%a) or qualify the basename (%a)"
···9991011 )
1000101210011013let raise_errorf ?(loc = none) ?(sub = []) ?(footnote=Fun.const None) =
10021002- Format.kdprintf (fun txt -> raise (Error (mkerror loc sub footnote txt)))
10141014+ Fmt.kdoc_printf (fun txt -> raise (Error (mkerror loc sub footnote txt)))
+23-20
parsing/location.mli
···8888(** {1 Toplevel-specific functions} *)
89899090val echo_eof: unit -> unit
9191-val separate_new_message: formatter -> unit
9191+val separate_new_message: unit Format_doc.printer
9292val reset: unit -> unit
93939494···169169 (** In -absname mode, return the absolute path for this filename.
170170 Otherwise, returns the filename unchanged. *)
171171172172-val print_filename: formatter -> string -> unit
173173-174174-val print_loc: formatter -> t -> unit
175175-val print_locs: formatter -> t list -> unit
172172+module Compat: sig
173173+ val print_filename: formatter -> string -> unit
174174+ val print_loc: formatter -> t -> unit
175175+ val print_locs: formatter -> t list -> unit
176176+ val separate_new_message: formatter -> unit -> unit
177177+end
176178179179+val print_filename: string Format_doc.printer
180180+val print_loc: t Format_doc.printer
181181+val print_locs: t list Format_doc.printer
177182178183(** {1 Toplevel-specific location highlighting} *)
179184···185190186191(** {2 The type of reports and report printers} *)
187192188188-type msg = (Format.formatter -> unit) loc
193193+type msg = Format_doc.t loc
189194190190-val msg: ?loc:t -> ('a, Format.formatter, unit, msg) format4 -> 'a
195195+val msg: ?loc:t -> ('a, Format_doc.formatter, unit, msg) format4 -> 'a
191196192197type report_kind =
193198 | Report_error
···200205 kind : report_kind;
201206 main : msg;
202207 sub : msg list;
203203- footnote: unit -> (Format.formatter -> unit) option
208208+ footnote: Format_doc.t option
204209}
205210206211type report_printer = {
···213218 pp_main_loc : report_printer -> report ->
214219 Format.formatter -> t -> unit;
215220 pp_main_txt : report_printer -> report ->
216216- Format.formatter -> (Format.formatter -> unit) -> unit;
221221+ Format.formatter -> Format_doc.t -> unit;
217222 pp_submsgs : report_printer -> report ->
218223 Format.formatter -> msg list -> unit;
219224 pp_submsg : report_printer -> report ->
···221226 pp_submsg_loc : report_printer -> report ->
222227 Format.formatter -> t -> unit;
223228 pp_submsg_txt : report_printer -> report ->
224224- Format.formatter -> (Format.formatter -> unit) -> unit;
229229+ Format.formatter -> Format_doc.t -> unit;
225230}
226231(** A printer for [report]s, defined using open-recursion.
227232 The goal is to make it easy to define new printers by re-using code from
···322327type error = report
323328(** An [error] is a [report] which [report_kind] must be [Report_error]. *)
324329325325-type delayed_msg = unit -> (formatter->unit) option
330330+type delayed_msg = unit -> Format_doc.t option
326331327327-val error: ?loc:t -> ?sub:msg list -> ?footnote:delayed_msg-> string -> error
332332+val error: ?loc:t -> ?sub:msg list -> ?footnote:delayed_msg -> string -> error
328333329329-val errorf:
330330- ?loc:t -> ?sub:msg list -> ?footnote:delayed_msg ->
331331- ('a, Format.formatter, unit, error) format4 -> 'a
334334+val errorf: ?loc:t -> ?sub:msg list -> ?footnote:delayed_msg ->
335335+ ('a, Format_doc.formatter, unit, error) format4 -> 'a
332336333333-val error_of_printer:
334334- ?loc:t -> ?sub:msg list -> ?footnote:delayed_msg ->
335335- (formatter -> 'a -> unit) -> 'a -> error
337337+val error_of_printer: ?loc:t -> ?sub:msg list -> ?footnote:delayed_msg ->
338338+ (Format_doc.formatter -> 'a -> unit) -> 'a -> error
336339337337-val error_of_printer_file: (formatter -> 'a -> unit) -> 'a -> error
340340+val error_of_printer_file: (Format_doc.formatter -> 'a -> unit) -> 'a -> error
338341339342340343(** {1 Automatically reporting errors for raised exceptions} *)
···358361 printed. The exception will be caught, but nothing will be printed *)
359362360363val raise_errorf: ?loc:t -> ?sub:msg list -> ?footnote:delayed_msg ->
361361- ('a, Format.formatter, unit, 'b) format4 -> 'a
364364+ ('a, Format_doc.formatter, unit, 'b) format4 -> 'a
362365363366val report_exception: formatter -> exn -> unit
364367(** Reraise the exception if it is unknown. *)
+6-6
parsing/parse.ml
···138138 Location.errorf ~loc
139139 "In this scoped type, variable %a \
140140 is reserved for the local type %a."
141141- (Style.as_inline_code Pprintast.tyvar) var
141141+ (Style.as_inline_code Pprintast.Doc.tyvar) var
142142 Style.inline_code var
143143 | Other loc ->
144144 Location.errorf ~loc "Syntax error"
···148148 | Invalid_package_type (loc, ipt) ->
149149 let invalid ppf ipt = match ipt with
150150 | Syntaxerr.Parameterized_types ->
151151- Format.fprintf ppf "parametrized types are not supported"
151151+ Format_doc.fprintf ppf "parametrized types are not supported"
152152 | Constrained_types ->
153153- Format.fprintf ppf "constrained types are not supported"
153153+ Format_doc.fprintf ppf "constrained types are not supported"
154154 | Private_types ->
155155- Format.fprintf ppf "private types are not supported"
155155+ Format_doc.fprintf ppf "private types are not supported"
156156 | Not_with_type ->
157157- Format.fprintf ppf "only %a constraints are supported"
157157+ Format_doc.fprintf ppf "only %a constraints are supported"
158158 Style.inline_code "with type t ="
159159 | Neither_identifier_nor_with_type ->
160160- Format.fprintf ppf
160160+ Format_doc.fprintf ppf
161161 "only module type identifier and %a constraints are supported"
162162 Style.inline_code "with type"
163163 in
+42-32
parsing/pprintast.ml
···9494let needs_spaces txt =
9595 first_is '*' txt || last_is '*' txt
96969797+let tyvar_of_name s =
9898+ if String.length s >= 2 && s.[1] = '\'' then
9999+ (* without the space, this would be parsed as
100100+ a character literal *)
101101+ "' " ^ s
102102+ else if Lexer.is_keyword s then
103103+ "'\\#" ^ s
104104+ else if String.equal s "_" then
105105+ s
106106+ else
107107+ "'" ^ s
108108+109109+module Doc = struct
97110(* Turn an arbitrary variable name into a valid OCaml identifier by adding \#
98111 in case it is a keyword, or parenthesis when it is an infix or prefix
99112 operator. *)
100100-let ident_of_name ppf txt =
101101- let format : (_, _, _) format =
102102- if Lexer.is_keyword txt then "\\#%s"
103103- else if not (needs_parens txt) then "%s"
104104- else if needs_spaces txt then "(@;%s@;)"
105105- else "(%s)"
106106- in fprintf ppf format txt
113113+ let ident_of_name ppf txt =
114114+ let format : (_, _, _) format =
115115+ if Lexer.is_keyword txt then "\\#%s"
116116+ else if not (needs_parens txt) then "%s"
117117+ else if needs_spaces txt then "(@;%s@;)"
118118+ else "(%s)"
119119+ in Format_doc.fprintf ppf format txt
107120108108-let ident_of_name_loc ppf s = ident_of_name ppf s.txt
109109-110110-let protect_longident ppf print_longident longprefix txt =
121121+ let protect_longident ppf print_longident longprefix txt =
111122 if not (needs_parens txt) then
112112- fprintf ppf "%a.%a" print_longident longprefix ident_of_name txt
123123+ Format_doc.fprintf ppf "%a.%a"
124124+ print_longident longprefix
125125+ ident_of_name txt
113126 else if needs_spaces txt then
114114- fprintf ppf "%a.(@;%s@;)" print_longident longprefix txt
127127+ Format_doc.fprintf ppf "%a.(@;%s@;)" print_longident longprefix txt
115128 else
116116- fprintf ppf "%a.(%s)" print_longident longprefix txt
129129+ Format_doc.fprintf ppf "%a.(%s)" print_longident longprefix txt
130130+131131+ let rec longident f = function
132132+ | Lident s -> ident_of_name f s
133133+ | Ldot(y,s) -> protect_longident f longident y s
134134+ | Lapply (y,s) ->
135135+ Format_doc.fprintf f "%a(%a)" longident y longident s
136136+137137+ let tyvar ppf s =
138138+ Format_doc.fprintf ppf "%s" (tyvar_of_name s)
139139+end
140140+141141+let longident ppf l = Format_doc.compat Doc.longident ppf l
142142+let ident_of_name ppf i = Format_doc.compat Doc.ident_of_name ppf i
143143+let ident_of_name_loc ppf s = ident_of_name ppf s.txt
117144118145type space_formatter = (unit, Format.formatter, unit) format
119146···225252 if b then (pp f "("; pp f first; fu f x; pp f last; pp f ")")
226253 else fu f x
227254228228-let rec longident f = function
229229- | Lident s -> ident_of_name f s
230230- | Ldot(y,s) -> protect_longident f longident y s
231231- | Lapply (y,s) ->
232232- pp f "%a(%a)" longident y longident s
233233-234255let longident_loc f x = pp f "%a" longident x.txt
235256236257let constant_desc f = function
···279300280301let constant_string f s = pp f "%S" s
281302282282-let tyvar_of_name s =
283283- if String.length s >= 2 && s.[1] = '\'' then
284284- (* without the space, this would be parsed as
285285- a character literal *)
286286- "' " ^ s
287287- else if Lexer.is_keyword s then
288288- "'\\#" ^ s
289289- else if String.equal s "_" then
290290- s
291291- else
292292- "'" ^ s
303303+293304294294-let tyvar ppf s =
295295- Format.fprintf ppf "%s" (tyvar_of_name s)
305305+let tyvar ppf v = Format_doc.compat Doc.tyvar ppf v
296306297307let tyvar_loc f str = tyvar f str.txt
298308let string_quot f x = pp f "`%a" ident_of_name x
+6
parsing/pprintast.mli
···5959 (** Print a type variable name as a valid identifier, taking care of the
6060 special treatment required for the single quote character in second
6161 position, or for keywords by escaping them with \#. No-op on "_". *)
6262+6363+(** {!Format_doc} functions for error messages *)
6464+module Doc:sig
6565+ val longident: Longident.t Format_doc.printer
6666+ val tyvar: string Format_doc.printer
6767+end
+5-3
testsuite/tests/formatting/errors_batch.ml
···22 include ocamlcommon;
33*)
4455+module Fmt = Format_doc
66+57let () =
68 let open Location in
79 (* Some dummy locations for demo purposes *)
···2729 } in
2830 let report = {
2931 kind = Report_error;
3030- main = msg ~loc:loc1 "%a" Format.pp_print_text
3232+ main = msg ~loc:loc1 "%a" Fmt.pp_print_text
3133 "These are the contents of the main error message. \
3234 It is very long and should wrap across several lines.";
3335 sub = [
3436 msg ~loc:loc2 "A located first sub-message.";
3535- msg ~loc:loc3 "%a" Format.pp_print_text
3737+ msg ~loc:loc3 "%a" Fmt.pp_print_text
3638 "Longer sub-messages that do not fit on the \
3739 same line as the location get indented.";
3840 msg "@[<v>This second sub-message does not have \
3941 a location;@,ghost locations of submessages are \
4042 not printed.@]";
4143 ];
4242- footnote=Fun.const None;
4444+ footnote=None;
4345 } in
4446 print_report Format.std_formatter report
+2-2
testsuite/tests/typing-misc/pr6416.ml
···5555 Constructors do not match:
5656 "A of t"
5757 is not the same as:
5858- "A of t"
5858+ "A of t/2"
5959 The type "t" is not equal to the type "t/2"
6060 Line 4, characters 9-19:
6161 Definition of type "t"
···121121 Constructors do not match:
122122 "A of T.t"
123123 is not the same as:
124124- "A of T.t"
124124+ "A of T/2.t"
125125 The type "T.t" is not equal to the type "T/2.t"
126126 Line 5, characters 6-34:
127127 Definition of module "T"
+1-1
testsuite/tests/utils/edit_distance.ml
···11(* TEST
22 include config;
33 include testing;
44- binary_modules = "config build_path_prefix_map misc identifiable numbers";
44+ binary_modules = "config build_path_prefix_map format_doc misc identifiable numbers";
55 bytecode;
66*)
77
+1-1
testsuite/tests/utils/find_first_mono.ml
···11(* TEST
22 include config;
33 include testing;
44- binary_modules = "config build_path_prefix_map misc";
44+ binary_modules = "config build_path_prefix_map format_doc misc";
55 bytecode;
66*)
77
···161161 if n >= Array.length !globals || n < 0
162162 then print_string "<global table overflow>"
163163 else match !globals.(n) with
164164- | Glob glob -> print_string
165165- (Format.asprintf "%a" Symtable.Global.description glob)
164164+ | Glob glob ->
165165+ let desc = Format_doc.compat Symtable.Global.description in
166166+ print_string (Format.asprintf "%a" desc glob)
166167 | Constant obj -> print_obj obj
167168 end
168169···190191 then print_string "<global table overflow>"
191192 else match !globals.(n) with
192193 | Glob glob ->
193193- print_string
194194- (Format.asprintf "%a" Symtable.Global.description glob)
194194+ let desc = Format_doc.compat Symtable.Global.description in
195195+ print_string (Format.asprintf "%a" desc glob)
195196 | Constant _ -> print_string "<unexpected constant>"
196197 end
197198
+4-4
tools/objinfo.ml
···122122 List.iter (fun (loc, item) ->
123123 let pp_loc fmt { Location.txt; loc } =
124124 Format.fprintf fmt "%a (%a)"
125125- Pprintast.longident txt Location.print_loc loc
125125+ Pprintast.longident txt Location.Compat.print_loc loc
126126 in
127127 Format.printf "@[<hov 2>%a:@ %a@]@;"
128128 Shape_reduce.print_result item pp_loc loc)
···156156 in
157157 let pp_loc fmt { Location.txt; loc } =
158158 Format.fprintf fmt "%s (%a)"
159159- txt Location.print_loc loc
159159+ txt Location.Compat.print_loc loc
160160 in
161161 Format.printf "@[<hov 2>%a:@ %a@]@;"
162162 Shape.Uid.print uid
···179179 printf "Globals defined:\n";
180180 Symtable.iter_global_map
181181 (fun global _ ->
182182- print_line
183183- (Format.asprintf "%a" Symtable.Global.description global)
182182+ let desc = Format_doc.compat Symtable.Global.description in
183183+ print_line (Format.asprintf "%a" desc global)
184184 )
185185 table
186186
+2-2
toplevel/byte/topeval.ml
···164164 begin match out_phr with
165165 | Ophr_signature [] -> ()
166166 | _ ->
167167- Location.separate_new_message ppf;
167167+ Location.Compat.separate_new_message ppf ();
168168 !print_out_phrase ppf out_phr;
169169 end;
170170 if Printexc.backtrace_status ()
···172172 match !backtrace with
173173 | None -> ()
174174 | Some b ->
175175- Location.separate_new_message ppf;
175175+ Location.Compat.separate_new_message ppf ();
176176 pp_print_string ppf b;
177177 pp_print_flush ppf ();
178178 backtrace := None;
+1
toplevel/byte/topmain.ml
···2424 get_code_pointer
2525 (Obj.repr (fun arg -> Trace.print_trace (current_environment()) arg))
26262727+module Printtyp = Printtyp.Compat
2728let dir_trace ppf lid =
2829 match Env.find_value_by_name lid !Topcommon.toplevel_env with
2930 | (path, desc) -> begin
+1
toplevel/byte/trace.ml
···66666767(* If a function returns a functional value, wrap it into a trace code *)
68686969+module Printtyp = Printtyp.Compat
6970let rec instrument_result env name ppf clos_typ =
7071 match get_desc (Ctype.expand_head env clos_typ) with
7172 | Tarrow(l, t1, t2, _) ->
+14-6
toplevel/genprintval.ml
···154154 ] : (Path.t * printer) list)
155155156156 let exn_printer ppf path exn =
157157- fprintf ppf "<printer %a raised an exception: %s>" Printtyp.path path
157157+ Format_doc.fprintf ppf "<printer %a raised an exception: %s>"
158158+ Printtyp.path path
158159 (Printexc.to_string exn)
159160160161 let out_exn path exn =
161162 Oval_printer (fun ppf -> exn_printer ppf path exn)
162163164164+ let user_printer path f ppf x =
165165+ Format_doc.deprecated_printer
166166+ (fun ppf ->
167167+ try f ppf x with
168168+ | exn -> Format_doc.compat (fun ppf -> exn_printer ppf path) ppf exn
169169+ )
170170+ ppf
171171+163172 let install_printer path ty fn =
164164- let print_val ppf obj =
165165- try fn ppf obj with exn -> exn_printer ppf path exn in
173173+ let print_val ppf obj = user_printer path fn ppf obj in
166174 let printer obj = Oval_printer (fun ppf -> print_val ppf obj) in
167175 printers := (path, Simple (ty, printer)) :: !printers
168176···174182 match gp with
175183 | Zero fn ->
176184 let out_printer obj =
177177- let printer ppf =
178178- try fn ppf obj with exn -> exn_printer ppf function_path exn in
185185+ let printer ppf = user_printer function_path fn ppf obj in
179186 Oval_printer printer in
180187 Zero out_printer
181188 | Succ fn ->
···616623 | _ ->
617624 (fun _obj ->
618625 let printer ppf =
619619- fprintf ppf "<internal error: incorrect arity for '%a'>"
626626+ Format_doc.fprintf ppf
627627+ "<internal error: incorrect arity for '%a'>"
620628 Printtyp.path path in
621629 Oval_printer printer)
622630
+1-1
toplevel/native/topeval.ml
···249249 begin match out_phr with
250250 | Ophr_signature [] -> ()
251251 | _ ->
252252- Location.separate_new_message ppf;
252252+ Location.Compat.separate_new_message ppf ();
253253 !print_out_phrase ppf out_phr;
254254 end;
255255 begin match out_phr with
+12-10
toplevel/topcommon.ml
···28282929let parse_toplevel_phrase = ref Parse.toplevel_phrase
3030let parse_use_file = ref Parse.use_file
3131-let print_location = Location.print_loc
3131+let print_location = Location.Compat.print_loc
3232let print_error = Location.print_report
3333let print_warning = Location.print_warning
3434let input_name = Location.input_name
···340340 Hashtbl.fold (fun dir _ acc -> dir::acc) directive_table []
341341342342module Style = Misc.Style
343343+let inline_code = Format_doc.compat Style.inline_code
343344344345let try_run_directive ppf dir_name pdir_arg =
345346 begin match get_directive dir_name with
346347 | None ->
347347- fprintf ppf "Unknown directive %a." Style.inline_code dir_name;
348348+ fprintf ppf "Unknown directive %a." inline_code dir_name;
348349 let directives = all_directive_names () in
349349- Misc.did_you_mean ppf
350350+ Format_doc.compat Misc.did_you_mean ppf
350351 (fun () -> Misc.spellcheck directives dir_name);
351352 fprintf ppf "@.";
352353 false
···360361 | exception _ ->
361362 fprintf ppf "Integer literal exceeds the range of \
362363 representable integers for directive %a.@."
363363- Style.inline_code dir_name;
364364+ inline_code dir_name;
364365 false
365366 end
366367 | Directive_int _, Some {pdira_desc = Pdir_int (_, Some _)} ->
367368 fprintf ppf "Wrong integer literal for directive %a.@."
368368- Style.inline_code dir_name;
369369+ inline_code dir_name;
369370 false
370371 | Directive_ident f, Some {pdira_desc = Pdir_ident lid} -> f lid; true
371372 | Directive_bool f, Some {pdira_desc = Pdir_bool b} -> f b; true
···387388 let pp_type ppf = function
388389 | `None -> Format.fprintf ppf "no argument"
389390 | `String ->
390390- Format.fprintf ppf "a %a literal" Style.inline_code "string"
391391+ Format.fprintf ppf "a %a literal" inline_code "string"
391392 | `Int ->
392392- Format.fprintf ppf "an %a literal" Style.inline_code "string"
393393+ Format.fprintf ppf "an %a literal" inline_code "string"
393394 | `Ident ->
394395 Format.fprintf ppf "an identifier"
395396 | `Bool ->
396396- Format.fprintf ppf "a %a literal" Style.inline_code "bool"
397397+ Format.fprintf ppf "a %a literal" inline_code "bool"
397398 in
398399 fprintf ppf "Directive %a expects %a, got %a.@."
399399- Style.inline_code dir_name pp_type dir_type pp_type arg_type;
400400+ inline_code dir_name pp_type dir_type pp_type arg_type;
400401 false
401402 end
402403403404(* Overriding exception printers with toplevel-specific ones *)
404405405406let loading_hint_printer ppf cu =
407407+ let open Format_doc in
406408 let global = Symtable.Global.Glob_compunit (Cmo_format.Compunit cu) in
407409 Symtable.report_error ppf (Symtable.Undefined_global global);
408410 let find_with_ext ext =
···417419 But very often they do. *)
418420 begin match List.find_map find_with_ext [".cma"; ".cmo"] with
419421 | Some path ->
420420- let load ppf path = Format.fprintf ppf "#load \"%s\"" path in
422422+ let load ppf path = Format_doc.fprintf ppf "#load \"%s\"" path in
421423 fprintf ppf
422424 "Found %a @,in the load paths. \
423425 @,Did you mean to load it using @,%a \
···119119exception Tags of label * label
120120121121let () =
122122+ let open Format_doc in
122123 Location.register_error_of_exn
123124 (function
124125 | Tags (l, l') ->
125125- let pp_tag ppf s = Format.fprintf ppf "`%s" s in
126126+ let pp_tag ppf s = fprintf ppf "`%s" s in
126127 let inline_tag = Misc.Style.as_inline_code pp_tag in
127128 Some
128129 Location.
+29-27
typing/env.ml
···3512351235133513(* Error report *)
3514351435153515-open Format
35153515+open Format_doc
3516351635173517(* Forward declarations *)
3518351835193519-let print_longident =
35203520- ref ((fun _ _ -> assert false) : formatter -> Longident.t -> unit)
35193519+let print_longident : Longident.t printer ref = ref (fun _ _ -> assert false)
35203520+35213521+let pp_longident ppf l = !print_longident ppf l
3521352235223522-let print_path =
35233523- ref ((fun _ _ -> assert false) : formatter -> Path.t -> unit)
35233523+let print_path: Path.t printer ref = ref (fun _ _ -> assert false)
35243524+let pp_path ppf l = !print_path ppf l
3524352535253526let spellcheck ppf extract env lid =
35263527 let choices ~path name = Misc.spellcheck (extract path env) name in
···3560356135613562module Style = Misc.Style
3562356335643564+let quoted_longident = Style.as_inline_code pp_longident
35653565+35633566let report_lookup_error _loc env ppf = function
35643567 | Unbound_value(lid, hint) -> begin
35653565- fprintf ppf "Unbound value %a"
35663566- (Style.as_inline_code !print_longident) lid;
35683568+ fprintf ppf "Unbound value %a" quoted_longident lid;
35673569 spellcheck ppf extract_values env lid;
35683570 match hint with
35693571 | No_hint -> ()
···35793581 end
35803582 | Unbound_type lid ->
35813583 fprintf ppf "Unbound type constructor %a"
35823582- (Style.as_inline_code !print_longident) lid;
35843584+ quoted_longident lid;
35833585 spellcheck ppf extract_types env lid;
35843586 | Unbound_module lid -> begin
35853587 fprintf ppf "Unbound module %a"
35863586- (Style.as_inline_code !print_longident) lid;
35883588+ quoted_longident lid;
35873589 match find_modtype_by_name lid env with
35883590 | exception Not_found -> spellcheck ppf extract_modules env lid;
35893591 | _ ->
35903592 fprintf ppf
35913593 "@.@[@{<hint>Hint@}: There is a module type named %a, %s@]"
35923592- (Style.as_inline_code !print_longident) lid
35943594+ quoted_longident lid
35933595 "but module types are not modules"
35943596 end
35953597 | Unbound_constructor lid ->
35963598 fprintf ppf "Unbound constructor %a"
35973597- (Style.as_inline_code !print_longident) lid;
35993599+ quoted_longident lid;
35983600 spellcheck ppf extract_constructors env lid;
35993601 | Unbound_label lid ->
36003602 fprintf ppf "Unbound record field %a"
36013601- (Style.as_inline_code !print_longident) lid;
36033603+ quoted_longident lid;
36023604 spellcheck ppf extract_labels env lid;
36033605 | Unbound_class lid -> begin
36043606 fprintf ppf "Unbound class %a"
36053605- (Style.as_inline_code !print_longident) lid;
36073607+ quoted_longident lid;
36063608 match find_cltype_by_name lid env with
36073609 | exception Not_found -> spellcheck ppf extract_classes env lid;
36083610 | _ ->
36093611 fprintf ppf
36103612 "@.@[@{<hint>Hint@}: There is a class type named %a, %s@]"
36113611- (Style.as_inline_code !print_longident) lid
36133613+ quoted_longident lid
36123614 "but classes are not class types"
36133615 end
36143616 | Unbound_modtype lid -> begin
36153617 fprintf ppf "Unbound module type %a"
36163616- (Style.as_inline_code !print_longident) lid;
36183618+ quoted_longident lid;
36173619 match find_module_by_name lid env with
36183620 | exception Not_found -> spellcheck ppf extract_modtypes env lid;
36193621 | _ ->
36203622 fprintf ppf
36213623 "@.@[@{<hint>Hint@}: There is a module named %a, %s@]"
36223622- (Style.as_inline_code !print_longident) lid
36243624+ quoted_longident lid
36233625 "but modules are not module types"
36243626 end
36253627 | Unbound_cltype lid ->
36263628 fprintf ppf "Unbound class type %a"
36273627- (Style.as_inline_code !print_longident) lid;
36293629+ quoted_longident lid;
36283630 spellcheck ppf extract_cltypes env lid;
36293631 | Unbound_instance_variable s ->
36303632 fprintf ppf "Unbound instance variable %a" Style.inline_code s;
···36373639 fprintf ppf
36383640 "The instance variable %a@ \
36393641 cannot be accessed from the definition of another instance variable"
36403640- (Style.as_inline_code !print_longident) lid
36423642+ quoted_longident lid
36413643 | Masked_self_variable lid ->
36423644 fprintf ppf
36433645 "The self variable %a@ \
36443646 cannot be accessed from the definition of an instance variable"
36453645- (Style.as_inline_code !print_longident) lid
36473647+ quoted_longident lid
36463648 | Masked_ancestor_variable lid ->
36473649 fprintf ppf
36483650 "The ancestor variable %a@ \
36493651 cannot be accessed from the definition of an instance variable"
36503650- (Style.as_inline_code !print_longident) lid
36523652+ quoted_longident lid
36513653 | Illegal_reference_to_recursive_module ->
36523654 fprintf ppf "Illegal recursive module reference"
36533655 | Structure_used_as_functor lid ->
36543656 fprintf ppf "@[The module %a is a structure, it cannot be applied@]"
36553655- (Style.as_inline_code !print_longident) lid
36573657+ quoted_longident lid
36563658 | Abstract_used_as_functor lid ->
36573659 fprintf ppf "@[The module %a is abstract, it cannot be applied@]"
36583658- (Style.as_inline_code !print_longident) lid
36603660+ quoted_longident lid
36593661 | Functor_used_as_structure lid ->
36603662 fprintf ppf "@[The module %a is a functor, \
36613661- it cannot have any components@]" !print_longident lid
36633663+ it cannot have any components@]" pp_longident lid
36623664 | Abstract_used_as_structure lid ->
36633665 fprintf ppf "@[The module %a is abstract, \
36643666 it cannot have any components@]"
36653665- (Style.as_inline_code !print_longident) lid
36673667+ quoted_longident lid
36663668 | Generative_used_as_applicative lid ->
36673669 fprintf ppf "@[The functor %a is generative,@ it@ cannot@ be@ \
36683670 applied@ in@ type@ expressions@]"
36693669- (Style.as_inline_code !print_longident) lid
36713671+ quoted_longident lid
36703672 | Cannot_scrape_alias(lid, p) ->
36713673 let cause =
36723674 if Current_unit_name.is_path p then "is the current compilation unit"
···36743676 in
36753677 fprintf ppf
36763678 "The module %a is an alias for module %a, which %s"
36773677- (Style.as_inline_code !print_longident) lid
36783678- (Style.as_inline_code !print_path) p cause
36793679+ quoted_longident lid
36803680+ (Style.as_inline_code pp_path) p cause
3679368136803682let report_error ppf = function
36813683 | Missing_module(_, path1, path2) ->
+4-6
typing/env.mli
···447447448448exception Error of error
449449450450-open Format
451451-452452-val report_error: formatter -> error -> unit
453450454454-val report_lookup_error: Location.t -> t -> formatter -> lookup_error -> unit
451451+val report_error: error Format_doc.printer
455452453453+val report_lookup_error: Location.t -> t -> lookup_error Format_doc.printer
456454val in_signature: bool -> t -> t
457455458456val is_in_signature: t -> bool
···482480(* Forward declaration to break mutual recursion with Ctype. *)
483481val same_constr: (t -> type_expr -> type_expr -> bool) ref
484482(* Forward declaration to break mutual recursion with Printtyp. *)
485485-val print_longident: (Format.formatter -> Longident.t -> unit) ref
483483+val print_longident: Longident.t Format_doc.printer ref
486484(* Forward declaration to break mutual recursion with Printtyp. *)
487487-val print_path: (Format.formatter -> Path.t -> unit) ref
485485+val print_path: Path.t Format_doc.printer ref
488486489487490488(** Folds *)
···1414(* *)
1515(**************************************************************************)
16161717-open Format
1818-1917(* Convert environment summaries to environments *)
20182119val env_from_summary : Env.summary -> Subst.t -> Env.t
···33313432exception Error of error
35333636-val report_error: formatter -> error -> unit
3434+val report_error: error Format_doc.printer
+3-3
typing/errortrace.ml
···1616(**************************************************************************)
17171818open Types
1919-open Format
1919+open Format_doc
20202121type position = First | Second
2222···100100101101type first_class_module =
102102 | Package_cannot_scrape of Path.t
103103- | Package_inclusion of (Format.formatter -> unit)
104104- | Package_coercion of (Format.formatter -> unit)
103103+ | Package_inclusion of Format_doc.doc
104104+ | Package_coercion of Format_doc.doc
105105106106type ('a, 'variety) elt =
107107 (* Common *)
+3-3
typing/errortrace.mli
···2020type position = First | Second
21212222val swap_position : position -> position
2323-val print_pos : Format.formatter -> position -> unit
2323+val print_pos : position Format_doc.printer
24242525type expanded_type = { ty: type_expr; expanded: type_expr }
2626···86868787type first_class_module =
8888 | Package_cannot_scrape of Path.t
8989- | Package_inclusion of (Format.formatter -> unit)
9090- | Package_coercion of (Format.formatter -> unit)
8989+ | Package_inclusion of Format_doc.doc
9090+ | Package_coercion of Format_doc.doc
91919292type ('a, 'variety) elt =
9393 (* Common *)
+7-7
typing/ident.ml
···138138 | _ -> false
139139140140let print ~with_scope ppf =
141141- let open Format in
141141+ let open Format_doc in
142142 function
143143 | Global name -> fprintf ppf "%s!" name
144144 | Predef { name; stamp = n } ->
145145 fprintf ppf "%s%s!" name
146146- (if !Clflags.unique_ids then sprintf "/%i" n else "")
146146+ (if !Clflags.unique_ids then asprintf "/%i" n else "")
147147 | Local { name; stamp = n } ->
148148 fprintf ppf "%s%s" name
149149- (if !Clflags.unique_ids then sprintf "/%i" n else "")
149149+ (if !Clflags.unique_ids then asprintf "/%i" n else "")
150150 | Scoped { name; stamp = n; scope } ->
151151 fprintf ppf "%s%s%s" name
152152- (if !Clflags.unique_ids then sprintf "/%i" n else "")
153153- (if with_scope then sprintf "[%i]" scope else "")
152152+ (if !Clflags.unique_ids then asprintf "/%i" n else "")
153153+ (if with_scope then asprintf "[%i]" scope else "")
154154155155let print_with_scope ppf id = print ~with_scope:true ppf id
156156157157-let print ppf id = print ~with_scope:false ppf id
158158-157157+let doc_print ppf id = print ~with_scope:false ppf id
158158+let print ppf id = Format_doc.compat doc_print ppf id
159159(* For the documentation of ['a Ident.tbl], see ident.mli.
160160161161 The implementation is a copy-paste specialization of
+2-1
typing/ident.mli
···2424 - [compare] compares identifiers by binding location
2525*)
26262727-val print_with_scope : Format.formatter -> t -> unit
2727+val doc_print: t Format_doc.printer
2828+val print_with_scope : t Format_doc.printer
2829 (** Same as {!print} except that it will also add a "[n]" suffix
2930 if the scope of the argument is [n]. *)
3031
+10-17
typing/includeclass.ml
···4040 cty1.cty_params cty1.cty_type
4141 cty2.cty_params cty2.cty_type
42424343-open Format
4343+open Format_doc
4444open Ctype
45454646(*
···5050*)
51515252let include_err mode ppf =
5353+ let msg fmt = Format_doc.Core.msg fmt in
5354 function
5455 | CM_Virtual_class ->
5556 fprintf ppf "A class cannot be changed from virtual to concrete"
···5859 "The classes do not have the same number of type parameters"
5960 | CM_Type_parameter_mismatch (n, env, err) ->
6061 Printtyp.report_equality_error ppf mode env err
6161- (function ppf ->
6262- fprintf ppf "The %d%s type parameter has type"
6262+ (msg "The %d%s type parameter has type"
6363 n (Misc.ordinal_suffix n))
6464- (function ppf ->
6565- fprintf ppf "but is expected to have type")
6464+ (msg "but is expected to have type")
6665 | CM_Class_type_mismatch (env, cty1, cty2) ->
6766 Printtyp.wrap_printing_env ~error:true env (fun () ->
6867 fprintf ppf
···7271 Printtyp.class_type cty2)
7372 | CM_Parameter_mismatch (n, env, err) ->
7473 Printtyp.report_moregen_error ppf mode env err
7575- (function ppf ->
7676- fprintf ppf "The %d%s parameter has type"
7474+ (msg "The %d%s parameter has type"
7775 n (Misc.ordinal_suffix n))
7878- (function ppf ->
7979- fprintf ppf "but is expected to have type")
7676+ (msg "but is expected to have type")
8077 | CM_Val_type_mismatch (lab, env, err) ->
8178 Printtyp.report_comparison_error ppf mode env err
8282- (function ppf ->
8383- fprintf ppf "The instance variable %s@ has type" lab)
8484- (function ppf ->
8585- fprintf ppf "but is expected to have type")
7979+ (msg "The instance variable %s@ has type" lab)
8080+ (msg "but is expected to have type")
8681 | CM_Meth_type_mismatch (lab, env, err) ->
8782 Printtyp.report_comparison_error ppf mode env err
8888- (function ppf ->
8989- fprintf ppf "The method %s@ has type" lab)
9090- (function ppf ->
9191- fprintf ppf "but is expected to have type")
8383+ (msg "The method %s@ has type" lab)
8484+ (msg "but is expected to have type")
9285 | CM_Non_mutable_value lab ->
9386 fprintf ppf
9487 "@[The non-mutable instance variable %s cannot become mutable@]" lab
+1-2
typing/includeclass.mli
···17171818open Types
1919open Ctype
2020-open Format
21202221val class_types:
2322 Env.t -> class_type -> class_type -> class_match_failure list
···3029 class_match_failure list
31303231val report_error :
3333- Printtyp.type_or_scheme -> formatter -> class_match_failure list -> unit
3232+ Printtyp.type_or_scheme -> class_match_failure list Format_doc.printer
+35-32
typing/includecore.ml
···208208 | Immediate of Type_immediacy.Violation.t
209209210210module Style = Misc.Style
211211+module Fmt = Format_doc
211212212213let report_primitive_mismatch first second ppf err =
213213- let pr fmt = Format.fprintf ppf fmt in
214214+ let pr fmt = Fmt.fprintf ppf fmt in
214215 match (err : primitive_mismatch) with
215216 | Name ->
216217 pr "The names of the primitives are not the same"
···231232 n (Misc.ordinal_suffix n)
232233233234let report_value_mismatch first second env ppf err =
234234- let pr fmt = Format.fprintf ppf fmt in
235235+ let pr fmt = Fmt.fprintf ppf fmt in
235236 pr "@ ";
236237 match (err : value_mismatch) with
237238 | Primitive_mismatch pm ->
···239240 | Not_a_primitive ->
240241 pr "The implementation is not a primitive."
241242 | Type trace ->
243243+ let msg = Fmt.Core.msg in
242244 Printtyp.report_moregen_error ppf Type_scheme env trace
243243- (fun ppf -> Format.fprintf ppf "The type")
244244- (fun ppf -> Format.fprintf ppf "is not compatible with the type")
245245+ (msg "The type")
246246+ (msg "is not compatible with the type")
245247246248let report_type_inequality env ppf err =
249249+ let msg = Fmt.Core.msg in
247250 Printtyp.report_equality_error ppf Type_scheme env err
248248- (fun ppf -> Format.fprintf ppf "The type")
249249- (fun ppf -> Format.fprintf ppf "is not equal to the type")
251251+ (msg "The type")
252252+ (msg "is not equal to the type")
250253251254let report_privacy_mismatch ppf err =
252255 let singular, item =
···256259 | Private_record_type -> true, "record constructor"
257260 | Private_extensible_variant -> true, "extensible variant"
258261 | Private_row_type -> true, "row type"
259259- in Format.fprintf ppf "%s %s would be revealed."
262262+ in Format_doc.fprintf ppf "%s %s would be revealed."
260263 (if singular then "A private" else "Private")
261264 item
262265···265268 | Type err ->
266269 report_type_inequality env ppf err
267270 | Mutability ord ->
268268- Format.fprintf ppf "%s is mutable and %s is not."
271271+ Format_doc.fprintf ppf "%s is mutable and %s is not."
269272 (String.capitalize_ascii (choose ord first second))
270273 (choose_other ord first second)
271274272275let pp_record_diff first second prefix decl env ppf (x : record_change) =
273276 match x with
274277 | Delete cd ->
275275- Format.fprintf ppf "%aAn extra field, %a, is provided in %s %s."
278278+ Fmt.fprintf ppf "%aAn extra field, %a, is provided in %s %s."
276279 prefix x Style.inline_code (Ident.name cd.delete.ld_id) first decl
277280 | Insert cd ->
278278- Format.fprintf ppf "%aA field, %a, is missing in %s %s."
281281+ Fmt.fprintf ppf "%aA field, %a, is missing in %s %s."
279282 prefix x Style.inline_code (Ident.name cd.insert.ld_id) first decl
280283 | Change Type {got=lbl1; expected=lbl2; reason} ->
281281- Format.fprintf ppf
284284+ Fmt.fprintf ppf
282285 "@[<hv>%aFields do not match:@;<1 2>\
283286 %a@ is not the same as:\
284287 @;<1 2>%a@ %a@]"
···287290 (Style.as_inline_code Printtyp.label) lbl2
288291 (report_label_mismatch first second env) reason
289292 | Change Name n ->
290290- Format.fprintf ppf "%aFields have different names, %a and %a."
293293+ Fmt.fprintf ppf "%aFields have different names, %a and %a."
291294 prefix x
292295 Style.inline_code n.got
293296 Style.inline_code n.expected
294297 | Swap sw ->
295295- Format.fprintf ppf "%aFields %a and %a have been swapped."
298298+ Fmt.fprintf ppf "%aFields %a and %a have been swapped."
296299 prefix x
297300 Style.inline_code sw.first
298301 Style.inline_code sw.last
299302 | Move {name; got; expected } ->
300300- Format.fprintf ppf
303303+ Fmt.fprintf ppf
301304 "@[<2>%aField %a has been moved@ from@ position %d@ to %d.@]"
302305 prefix x Style.inline_code name expected got
303306304307let report_patch pr_diff first second decl env ppf patch =
305305- let nl ppf () = Format.fprintf ppf "@," in
308308+ let nl ppf () = Fmt.fprintf ppf "@," in
306309 let no_prefix _ppf _ = () in
307310 match patch with
308311 | [ elt ] ->
309309- Format.fprintf ppf "@[<hv>%a@]"
312312+ Fmt.fprintf ppf "@[<hv>%a@]"
310313 (pr_diff first second no_prefix decl env) elt
311314 | _ ->
312315 let pp_diff = pr_diff first second Diffing_with_keys.prefix decl env in
313313- Format.fprintf ppf "@[<hv>%a@]"
314314- (Format.pp_print_list ~pp_sep:nl pp_diff) patch
316316+ Fmt.fprintf ppf "@[<hv>%a@]"
317317+ (Fmt.pp_print_list ~pp_sep:nl pp_diff) patch
315318316319let report_record_mismatch first second decl env ppf err =
317317- let pr fmt = Format.fprintf ppf fmt in
320320+ let pr fmt = Fmt.fprintf ppf fmt in
318321 match err with
319322 | Label_mismatch patch ->
320323 report_patch pp_record_diff first second decl env ppf patch
···324327 "uses unboxed float representation"
325328326329let report_constructor_mismatch first second decl env ppf err =
327327- let pr fmt = Format.fprintf ppf fmt in
330330+ let pr fmt = Fmt.fprintf ppf fmt in
328331 match (err : constructor_mismatch) with
329332 | Type err -> report_type_inequality env ppf err
330333 | Arity -> pr "They have different arities."
···342345let pp_variant_diff first second prefix decl env ppf (x : variant_change) =
343346 match x with
344347 | Delete cd ->
345345- Format.fprintf ppf "%aAn extra constructor, %a, is provided in %s %s."
348348+ Fmt.fprintf ppf "%aAn extra constructor, %a, is provided in %s %s."
346349 prefix x Style.inline_code (Ident.name cd.delete.cd_id) first decl
347350 | Insert cd ->
348348- Format.fprintf ppf "%aA constructor, %a, is missing in %s %s."
351351+ Fmt.fprintf ppf "%aA constructor, %a, is missing in %s %s."
349352 prefix x Style.inline_code (Ident.name cd.insert.cd_id) first decl
350353 | Change Type {got; expected; reason} ->
351351- Format.fprintf ppf
354354+ Fmt.fprintf ppf
352355 "@[<hv>%aConstructors do not match:@;<1 2>\
353356 %a@ is not the same as:\
354357 @;<1 2>%a@ %a@]"
···357360 (Style.as_inline_code Printtyp.constructor) expected
358361 (report_constructor_mismatch first second decl env) reason
359362 | Change Name n ->
360360- Format.fprintf ppf
363363+ Fmt.fprintf ppf
361364 "%aConstructors have different names, %a and %a."
362365 prefix x
363366 Style.inline_code n.got
364367 Style.inline_code n.expected
365368 | Swap sw ->
366366- Format.fprintf ppf
369369+ Fmt.fprintf ppf
367370 "%aConstructors %a and %a have been swapped."
368371 prefix x
369372 Style.inline_code sw.first
370373 Style.inline_code sw.last
371374 | Move {name; got; expected} ->
372372- Format.fprintf ppf
375375+ Fmt.fprintf ppf
373376 "@[<2>%aConstructor %a has been moved@ from@ position %d@ to %d.@]"
374377 prefix x Style.inline_code name expected got
375378376379let report_extension_constructor_mismatch first second decl env ppf err =
377377- let pr fmt = Format.fprintf ppf fmt in
380380+ let pr fmt = Fmt.fprintf ppf fmt in
378381 match (err : extension_constructor_mismatch) with
379382 | Constructor_privacy ->
380383 pr "Private extension constructor(s) would be revealed."
···390393391394392395let report_private_variant_mismatch first second decl env ppf err =
393393- let pr fmt = Format.fprintf ppf fmt in
394394- let pp_tag ppf x = Format.fprintf ppf "`%s" x in
396396+ let pr fmt = Fmt.fprintf ppf fmt in
397397+ let pp_tag ppf x = Fmt.fprintf ppf "`%s" x in
395398 match (err : private_variant_mismatch) with
396399 | Only_outer_closed ->
397400 (* It's only dangerous in one direction, so we don't have a position *)
···408411 report_type_inequality env ppf err
409412410413let report_private_object_mismatch env ppf err =
411411- let pr fmt = Format.fprintf ppf fmt in
414414+ let pr fmt = Fmt.fprintf ppf fmt in
412415 match (err : private_object_mismatch) with
413416 | Missing s ->
414417 pr "The implementation is missing the method %a" Style.inline_code s
415418 | Types err -> report_type_inequality env ppf err
416419417420let report_kind_mismatch first second ppf (kind1, kind2) =
418418- let pr fmt = Format.fprintf ppf fmt in
421421+ let pr fmt = Fmt.fprintf ppf fmt in
419422 let kind_to_string = function
420423 | Kind_abstract -> "abstract"
421424 | Kind_record -> "a record"
···428431 (kind_to_string kind2)
429432430433let report_type_mismatch first second decl env ppf err =
431431- let pr fmt = Format.fprintf ppf fmt in
434434+ let pr fmt = Fmt.fprintf ppf fmt in
432435 pr "@ ";
433436 match err with
434437 | Arity ->
···4949 | Oval_int64 of int64
5050 | Oval_nativeint of nativeint
5151 | Oval_list of out_value list
5252- | Oval_printer of (Format.formatter -> unit)
5252+ | Oval_printer of (Format_doc.formatter -> unit)
5353 | Oval_record of (out_ident * out_value) list
5454 | Oval_string of string * int * out_string (* string, size-to-print, kind *)
5555 | Oval_stuff of string
+7-7
typing/parmatch.ml
···18841884 | Seq.Cons (v, _rest) ->
18851885 if Warnings.is_active (Warnings.Partial_match "") then begin
18861886 let errmsg =
18871887- let buf = Buffer.create 16 in
18881888- let fmt = Format.formatter_of_buffer buf in
18891889- Format.fprintf fmt "@[<v>%a" Printpat.pretty_pat v;
18871887+ let doc = ref Format_doc.empty in
18881888+ let fmt = Format_doc.formatter doc in
18891889+ Format_doc.fprintf fmt "@[<v>%a" Printpat.top_pretty v;
18901890 if do_match (initial_only_guarded casel) [v] then
18911891- Format.fprintf fmt
18911891+ Format_doc.fprintf fmt
18921892 "@,(However, some guarded clause may match this value.)";
18931893 if contains_extension v then
18941894- Format.fprintf fmt
18941894+ Format_doc.fprintf fmt
18951895 "@,@[Matching over values of extensible variant types \
18961896 (the *extension* above)@,\
18971897 must include a wild card pattern@ in order to be exhaustive.@]"
18981898 ;
18991899- Format.fprintf fmt "@]@?";
19001900- Buffer.contents buf
18991899+ Format_doc.fprintf fmt "@]";
19001900+ Format_doc.(asprintf "%a" pp_doc) !doc
19011901 in
19021902 Location.prerr_warning loc (Warnings.Partial_match errmsg)
19031903 end;
+2-2
typing/path.ml
···104104let rec print ppf = function
105105 | Pident id -> Ident.print_with_scope ppf id
106106 | Pdot(p, s) | Pextra_ty (p, Pcstr_ty s) ->
107107- Format.fprintf ppf "%a.%s" print p s
108108- | Papply(p1, p2) -> Format.fprintf ppf "%a(%a)" print p1 print p2
107107+ Format_doc.fprintf ppf "%a.%s" print p s
108108+ | Papply(p1, p2) -> Format_doc.fprintf ppf "%a(%a)" print p1 print p2
109109 | Pextra_ty (p, Pext_ty) -> print ppf p
110110111111let rec head = function
+1-1
typing/path.mli
···6868 (* [paren] tells whether a path suffix needs parentheses *)
6969val head: t -> Ident.t
70707171-val print: Format.formatter -> t -> unit
7171+val print: t Format_doc.printer
72727373val heads: t -> Ident.t list
7474
+6-4
typing/persistent_env.ml
···243243 let warn = Warnings.No_cmi_file(name, None) in
244244 Location.prerr_warning loc warn
245245 | Cmi_format.Error err ->
246246- let msg = Format.asprintf "%a" Cmi_format.report_error err in
246246+ let msg = Format.asprintf "%a"
247247+ (Format_doc.compat Cmi_format.report_error) err in
247248 let warn = Warnings.No_cmi_file(name, Some msg) in
248249 Location.prerr_warning loc warn
249250 | Error err ->
250251 let msg =
251252 match err with
252253 | Illegal_renaming(name, ps_name, filename) ->
253253- Format.asprintf
254254+ Format_doc.doc_printf
254255 " %a@ contains the compiled interface for @ \
255256 %a when %a was expected"
256257 (Style.as_inline_code Location.print_filename) filename
···258259 Style.inline_code name
259260 | Inconsistent_import _ -> assert false
260261 | Need_recursive_types name ->
261261- Format.asprintf
262262+ Format_doc.doc_printf
262263 "%a uses recursive types"
263264 Style.inline_code name
264265 in
266266+ let msg = Format_doc.(asprintf "%a" pp_doc) msg in
265267 let warn = Warnings.No_cmi_file(name, Some msg) in
266268 Location.prerr_warning loc warn
267269···350352 ~exceptionally:(fun () -> remove_file filename)
351353352354let report_error ppf =
353353- let open Format in
355355+ let open Format_doc in
354356 function
355357 | Illegal_renaming(modname, ps_name, filename) -> fprintf ppf
356358 "Wrong file naming: %a@ contains the compiled interface for@ \
+1-1
typing/persistent_env.mli
···27272828exception Error of error
29293030-val report_error: Format.formatter -> error -> unit
3030+val report_error: error Format_doc.printer
31313232module Persistent_signature : sig
3333 type t =
+3-3
typing/primitive.ml
···232232let report_error ppf err =
233233 match err with
234234 | Old_style_float_with_native_repr_attribute ->
235235- Format.fprintf ppf "Cannot use %a in conjunction with %a/%a."
235235+ Format_doc.fprintf ppf "Cannot use %a in conjunction with %a/%a."
236236 Style.inline_code "float"
237237 Style.inline_code "[@unboxed]"
238238 Style.inline_code "[@untagged]"
239239 | Old_style_noalloc_with_noalloc_attribute ->
240240- Format.fprintf ppf "Cannot use %a in conjunction with %a."
240240+ Format_doc.fprintf ppf "Cannot use %a in conjunction with %a."
241241 Style.inline_code "noalloc"
242242 Style.inline_code "[@@noalloc]"
243243 | No_native_primitive_with_repr_attribute ->
244244- Format.fprintf ppf
244244+ Format_doc.fprintf ppf
245245 "@[The native code version of the primitive is mandatory@ \
246246 when attributes %a or %a are present.@]"
247247 Style.inline_code "[@untagged]"
+20-10
typing/printpat.ml
···1818open Asttypes
1919open Typedtree
2020open Types
2121-open Format
2121+open Format_doc
22222323let is_cons = function
2424| {cstr_name = "::"} -> true
···9999 | Tpat_lazy v ->
100100 fprintf ppf "@[<2>lazy@ %a@]" pretty_arg v
101101 | Tpat_alias (v, x,_,_) ->
102102- fprintf ppf "@[(%a@ as %a)@]" pretty_val v Ident.print x
102102+ fprintf ppf "@[(%a@ as %a)@]" pretty_val v Ident.doc_print x
103103 | Tpat_value v ->
104104 fprintf ppf "%a" pretty_val (v :> pattern)
105105 | Tpat_exception v ->
···144144 fprintf ppf "%s=%a;@ %a"
145145 lbl.lbl_name pretty_val v pretty_lvals rest
146146147147+let top_pretty ppf v =
148148+ fprintf ppf "@[%a@]" pretty_val v
149149+147150let pretty_pat ppf p =
148148- fprintf ppf "@[%a@]" pretty_val p
151151+ top_pretty ppf p ;
152152+ pp_print_flush ppf ()
149153150154type 'k matrix = 'k general_pattern list list
151155152156let pretty_line ppf line =
153153- Format.fprintf ppf "@[";
157157+ fprintf ppf "@[";
154158 List.iter (fun p ->
155155- Format.fprintf ppf "<%a>@ "
156156- pretty_val p
157157- ) line;
158158- Format.fprintf ppf "@]"
159159+ fprintf ppf "<%a>@ "
160160+ pretty_val p
161161+ ) line;
162162+ fprintf ppf "@]"
159163160164let pretty_matrix ppf (pss : 'k matrix) =
161161- Format.fprintf ppf "@[<v 2> %a@]"
162162- (Format.pp_print_list ~pp_sep:Format.pp_print_cut pretty_line)
165165+ fprintf ppf "@[<v 2> %a@]"
166166+ (pp_print_list ~pp_sep:pp_print_cut pretty_line)
163167 pss
168168+169169+module Compat = struct
170170+ let pretty_pat ppf x = compat pretty_pat ppf x
171171+ let pretty_line ppf x = compat pretty_line ppf x
172172+ let pretty_matrix ppf x = compat pretty_matrix ppf x
173173+end
+8-7
typing/printpat.mli
···17171818val pretty_const
1919 : Asttypes.constant -> string
2020-val pretty_val : Format.formatter -> 'k Typedtree.general_pattern -> unit
21202222-val pretty_pat
2323- : Format.formatter -> 'k Typedtree.general_pattern -> unit
2424-val pretty_line
2525- : Format.formatter -> 'k Typedtree.general_pattern list -> unit
2626-val pretty_matrix
2727- : Format.formatter -> 'k Typedtree.general_pattern list list -> unit
2121+val top_pretty: 'k Typedtree.general_pattern Format_doc.printer
2222+2323+module Compat: sig
2424+ val pretty_pat: Format.formatter -> 'k Typedtree.general_pattern -> unit
2525+ val pretty_line: Format.formatter -> 'k Typedtree.general_pattern list -> unit
2626+ val pretty_matrix:
2727+ Format.formatter -> 'k Typedtree.general_pattern list list -> unit
2828+end
+83-70
typing/printtyp.ml
···17171818open Misc
1919open Ctype
2020-open Format
2120open Longident
2221open Path
2322open Asttypes
···3029module Style = Misc.Style
31303231(* Print a long identifier *)
3333-let longident = Pprintast.longident
3232+3333+module Fmt = Format_doc
3434+open Format_doc
3535+3636+let longident = Pprintast.Doc.longident
34373538let () = Env.print_longident := longident
3639···798280838184 let pp ppf x =
8282- Format.pp_print_string ppf (Shape.Sig_component_kind.to_string x)
8585+ Fmt.pp_print_string ppf (Shape.Sig_component_kind.to_string x)
83868487 (** The two functions below should never access the filesystem,
8588 and thus use {!in_printing_env} rather than directly
···157160 end
158161159162 let pp_explanation ppf r=
160160- Format.fprintf ppf "@[<v 2>%a:@,Definition of %s %a@]"
163163+ Fmt.fprintf ppf "@[<v 2>%a:@,Definition of %s %a@]"
161164 Location.print_loc r.location (Sig_component_kind.to_string r.kind)
162165 Style.inline_code r.name
163166164167 let print_located_explanations ppf l =
165165- Format.fprintf ppf "@[<v>%a@]" (Format.pp_print_list pp_explanation) l
168168+ Fmt.fprintf ppf "@[<v>%a@]"
169169+ (Fmt.pp_print_list pp_explanation) l
166170167171 let reset () = explanations := M.empty
168172 let list_explanations () =
···172176173177174178 let print_toplevel_hint ppf l =
175175- let conj ppf () = Format.fprintf ppf " and@ " in
176176- let pp_namespace_plural ppf n = Format.fprintf ppf "%as" Namespace.pp n in
179179+ let conj ppf () = Fmt.fprintf ppf " and@ " in
180180+ let pp_namespace_plural ppf n = Fmt.fprintf ppf "%as" Namespace.pp n in
177181 let root_names = List.map (fun r -> r.kind, r.root_name) l in
178182 let unique_root_names = List.sort_uniq Stdlib.compare root_names in
179183 let submsgs = Array.make Namespace.size [] in
···184188 match names with
185189 | [] -> ()
186190 | [namespace, a] ->
187187- Format.fprintf ppf
191191+ Fmt.fprintf ppf
188192 "@,\
189193 @[<2>@{<hint>Hint@}: The %a %a has been defined multiple times@ \
190194 in@ this@ toplevel@ session.@ \
···193197 Namespace.pp namespace
194198 Style.inline_code a Namespace.pp namespace
195199 | (namespace, _) :: _ :: _ ->
196196- Format.fprintf ppf
200200+ Fmt.fprintf ppf
197201 "@,\
198202 @[<2>@{<hint>Hint@}: The %a %a have been defined multiple times@ \
199203 in@ this@ toplevel@ session.@ \
200204 Some toplevel values still refer to@ old@ versions@ of@ those@ %a.\
201205 @ Did you try to redefine them?@]"
202206 pp_namespace_plural namespace
203203- Format.(pp_print_list ~pp_sep:conj Style.inline_code)
207207+ Fmt.(pp_print_list ~pp_sep:conj Style.inline_code)
204208 (List.map snd names)
205209 pp_namespace_plural namespace in
206210 Array.iter (pp_submsg ppf) submsgs
···216220 | [], [] -> None
217221 | _ ->
218222 Some
219219- (Format.dprintf "%a%a"
223223+ (Fmt.doc_printf "%a%a"
220224 print_located_explanations l
221225 print_toplevel_hint ltop
222226 )
223223- let err_print ppf = Option.iter (Format.fprintf ppf "@,%t") (err_msg ())
227227+ let err_print ppf = Option.iter Fmt.(fprintf ppf "@,%a" pp_doc) (err_msg ())
224228225229 let exists () = M.cardinal !explanations >0
226230end
···438442 !Oprint.out_ident ppf (tree_of_path ~disambiguation:false None p)
439443440444let string_of_path p =
441441- Format.asprintf "%a" path p
445445+ Format.asprintf "%a" (Fmt.compat path) p
442446443447let strings_of_paths namespace p =
444448 let trees = List.map (tree_of_path namespace) p in
445445- List.map (Format.asprintf "%a" !Oprint.out_ident) trees
449449+ List.map (Fmt.asprintf "%a" !Oprint.out_ident) trees
446450447451let () = Env.print_path := path
448452···452456 | Trec_not -> Orec_not
453457 | Trec_first -> Orec_first
454458 | Trec_next -> Orec_next
455455-456459457460(* Normalize paths *)
458461···587590 if error then Env.without_cmis (wrap_printing_env env) f
588591 else wrap_printing_env env f
589592590590-let wrap_printing_env_error env f =
591591- let wrap_txt f fmt = wrap_printing_env ~error:true env (fun () -> f fmt) in
592592- let wrap (loc : _ Location.loc) = { loc with txt = wrap_txt loc.txt } in
593593- let err : Location.error = wrap_printing_env ~error:true env f in
594594- { Location.kind = err.kind;
595595- main = wrap err.main;
596596- sub = List.map wrap err.sub;
597597- footnote = (fun () -> wrap_printing_env ~error:true env (fun () ->
598598- Option.map wrap_txt (err.footnote ())));
599599- }
600600-601593let rec lid_of_path = function
602594 Path.Pident id ->
603595 Longident.Lident (Ident.name id)
···720712 | _ ->
721713 Btype.iter_type_expr f ty
722714715715+let quoted_ident ppf x =
716716+ Style.as_inline_code !Oprint.out_ident ppf x
717717+723718module Internal_names : sig
724719725720 val reset : unit -> unit
726721727722 val add : Path.t -> unit
728723729729- val print_explanations : Env.t -> Format.formatter -> unit
724724+ val print_explanations : Env.t -> Fmt.formatter -> unit
730725731726end = struct
732727···768763 fprintf ppf
769764 "@ @[<2>@{<hint>Hint@}:@ %a@ is an existential type@ \
770765 bound by the constructor@ %a.@]"
771771- (Style.as_inline_code !Oprint.out_ident) out_ident
766766+ quoted_ident out_ident
772767 Style.inline_code constr
773768 | out_ident :: out_idents ->
774769 fprintf ppf
775770 "@ @[<2>@{<hint>Hint@}:@ %a@ and %a@ are existential types@ \
776771 bound by the constructor@ %a.@]"
777777- (Format.pp_print_list
772772+ (Fmt.pp_print_list
778773 ~pp_sep:(fun ppf () -> fprintf ppf ",@ ")
779779- (Style.as_inline_code !Oprint.out_ident))
774774+ quoted_ident)
780775 (List.rev out_idents)
781781- (Style.as_inline_code !Oprint.out_ident) out_ident
776776+ quoted_ident out_ident
782777 Style.inline_code constr)
783778 constrs
784779···15871582 ext.ext_args
15881583 ext.ext_ret_type
15891584 in
15901590- Format.fprintf ppf "@[<hv>%a@]"
15851585+ Fmt.fprintf ppf "@[<hv>%a@]"
15911586 !Oprint.out_constr {
15921587 ocstr_name = name;
15931588 ocstr_args = args;
···19601955let rec functor_parameters ~sep custom_printer = function
19611956 | [] -> ignore
19621957 | [id,param] ->
19631963- Format.dprintf "%t%t"
19581958+ Fmt.dprintf "%t%t"
19641959 (custom_printer param)
19651960 (functor_param ~sep ~custom_printer id [])
19661961 | (id,param) :: q ->
19671967- Format.dprintf "%t%a%t"
19621962+ Fmt.dprintf "%t%a%t"
19681963 (custom_printer param)
19691964 sep ()
19701965 (functor_param ~sep ~custom_printer id q)
···20072002 begin match Conflicts.err_msg () with
20082003 | None -> ()
20092004 | Some msg ->
20102010- let conflicts = Format.asprintf "%t" msg in
20052005+ let conflicts = asprintf "%a" pp_doc msg in
20112006 Location.prerr_warning (Location.in_file sourcefile)
20122007 (Warnings.Erroneous_printed_signature conflicts);
20132008 Warnings.check_fatal ()
20142009 end;
20152015- fprintf ppf "%a" print_signature t
20102010+ compat print_signature ppf t
2016201120172012(* Trace-specific printing *)
20182013···20682063 else Diff(first,second)
20692064 end
2070206520662066+let pp_type ppf t =
20672067+ Style.as_inline_code !Oprint.out_type ppf t
20682068+20692069+let quoted_ident ppf t =
20702070+ Style.as_inline_code !Oprint.out_ident ppf t
20712071+20712072let type_expansion ppf = function
20722072- | Same t -> Style.as_inline_code !Oprint.out_type ppf t
20732073+ | Same t -> pp_type ppf t
20732074 | Diff(t,t') ->
20742075 fprintf ppf "@[<2>%a@ =@ %a@]"
20752075- (Style.as_inline_code !Oprint.out_type) t
20762076- (Style.as_inline_code !Oprint.out_type) t'
20762076+ pp_type t
20772077+ pp_type t'
2077207820782079let trees_of_trace mode =
20792080 List.map (Errortrace.map_diff (trees_of_type_expansion mode))
···20832084 Diff(tree_of_path (Some Type) tp, tree_of_path (Some Type) tp')
2084208520852086let type_path_expansion ppf = function
20862086- | Same p -> Style.as_inline_code !Oprint.out_ident ppf p
20872087+ | Same p -> quoted_ident ppf p
20872088 | Diff(p,p') ->
20882089 fprintf ppf "@[<2>%a@ =@ %a@]"
20892089- (Style.as_inline_code !Oprint.out_ident) p
20902090- (Style.as_inline_code !Oprint.out_ident) p'
20902090+ quoted_ident p
20912091+ quoted_ident p'
2091209220922093let rec trace fst txt ppf = function
20932094 | {Errortrace.got; expected} :: rem ->
···21492150 | Errortrace.Diff d :: rem -> d :: filter_trace keep_last rem
21502151 | _ :: rem -> filter_trace keep_last rem
2151215221522152-let type_path_list =
21532153- Format.pp_print_list ~pp_sep:(fun ppf () -> Format.pp_print_break ppf 2 0)
21542154- type_path_expansion
21532153+let type_path_list ppf l =
21542154+ Fmt.pp_print_list ~pp_sep:(fun ppf () -> Fmt.pp_print_break ppf 2 0)
21552155+ type_path_expansion ppf l
2155215621562157(* Hide variant name and var, to force printing the expanded type *)
21572158let hide_variant_name t =
···21782179 | _ -> prepare_expansion ty_exp
2179218021802181let print_path p =
21812181- Format.dprintf "%a" !Oprint.out_ident (tree_of_path (Some Type) p)
21822182+ Fmt.dprintf "%a" !Oprint.out_ident (tree_of_path (Some Type) p)
2182218321832184let print_tag ppf s = Style.inline_code ppf ("`" ^ s)
2184218521852185-let print_tags =
21862186- let comma ppf () = Format.fprintf ppf ",@ " in
21872187- Format.pp_print_list ~pp_sep:comma print_tag
21862186+let print_tags ppf tags =
21872187+ Fmt.(pp_print_list ~pp_sep:comma) print_tag ppf tags
2188218821892189let is_unit env ty =
21902190 match get_desc (Ctype.expand_head env ty) with
···22002200 Btype.backtrack snap;
22012201 res
2202220222032203-let explanation_diff env t3 t4 : (Format.formatter -> unit) option =
22032203+22042204+let explanation_diff env t3 t4 =
22042205 match get_desc t3, get_desc t4 with
22052206 | Tarrow (_, ty1, ty2, _), _
22062207 when is_unit env ty1 && unifiable env ty2 t4 ->
···22122213 | _, Tarrow (_, ty1, ty2, _)
22132214 when is_unit env ty1 && unifiable env t3 ty2 ->
22142215 Some (fun ppf ->
22152215- fprintf ppf
22162216+ fprintf ppf
22162217 "@,@[@{<hint>Hint@}: Did you forget to wrap the expression using \
22172218 %a?@]"
22182219 Style.inline_code "fun () ->"
···23432344 Style.(as_inline_code path) p
23442345 )
23452346 | Errortrace.Package_inclusion pr ->
23462346- Some(dprintf "@,@[%t@]" pr)
23472347+ Some(dprintf "@,@[%a@]" Fmt.pp_doc pr)
23472348 | Errortrace.Package_coercion pr ->
23482348- Some(dprintf "@,@[%t@]" pr)
23492349+ Some(dprintf "@,@[%a@]" Fmt.pp_doc pr)
2349235023502351let explanation (type variety) intro prev env
23512352 : (Errortrace.expanded_type, variety) Errortrace.elt -> _ = function
···23562357 match context, kind, prev with
23572358 | Some ctx, _, _ ->
23582359 reserve_names ctx;
23592359- dprintf "@[%t@;<1 2>%a@]" intro
23602360+ dprintf "@[%a@;<1 2>%a@]" pp_doc intro
23602361 (Style.as_inline_code type_expr_with_reserved_names) ctx
23612362 | None, Univ _, Some(Errortrace.Incompatible_fields {name; diff}) ->
23622363 explain_incompatible_fields name diff
···23972398let mismatch intro env trace =
23982399 Errortrace.explain trace (fun ~prev h -> explanation intro prev env h)
2399240024002400-let explain mis ppf =
24012401+let explain mis ppf =
24012402 match mis with
24022403 | None -> ()
24032404 | Some explain -> explain ppf
···24312432 | None -> ignore
24322433 | Some d ->
24332434 let d = Errortrace.map_diff (trees_of_type_expansion mode) d in
24342434- dprintf "%t@;<1 2>%a@ %t@;<1 2>%a"
24352435- txt_got type_expansion d.Errortrace.got
24362436- txt_but type_expansion d.Errortrace.expected
24352435+ dprintf "%a@;<1 2>%a@ %a@;<1 2>%a"
24362436+ pp_doc txt_got type_expansion d.Errortrace.got
24372437+ pp_doc txt_but type_expansion d.Errortrace.expected
2437243824382439let warn_on_missing_defs env ppf = function
24392440 | None -> ()
···24662467 let tr = trees_of_trace mode tr in
24672468 fprintf ppf
24682469 "@[<v>\
24692469- @[%t%t@]%a%t\
24702470+ @[%t%a@]%a%t\
24702471 @]"
24712472 head_error
24722472- ty_expect_explanation
24732473+ pp_doc ty_expect_explanation
24732474 (trace false (incompatibility_phrase trace_format)) tr
24742475 (explain mis);
24752476 if env <> Env.empty
···2483248424842485let report_error trace_format ppf mode env tr
24852486 ?(subst = [])
24862486- ?(type_expected_explanation = fun _ -> ())
24872487+ ?(type_expected_explanation = Fmt.empty)
24872488 txt1 txt2 =
24882489 wrap_printing_env ~error:true env (fun () ->
24892490 error trace_format mode subst env tr txt1 ppf txt2
···25772578 (trace filter_subtype_trace subtype_get_diff true keep_first txt1)
25782579 tr_sub;
25792580 if tr_unif = [] then fprintf ppf "@]" else
25802580- let mis = mismatch (dprintf "Within this type") env tr_unif in
25812581+ let mis = mismatch (doc_printf "Within this type") env tr_unif in
25812582 fprintf ppf "%a%t%t@]"
25822583 (trace filter_trace unification_get_diff false
25832584 (mis = None) "is not compatible with type") tr_unif
···25942595 [] -> assert false
25952596 | [tp] ->
25962597 fprintf ppf
25972597- "@[%t@;<1 2>%a@ \
25982598- %t@;<1 2>%a\
25982598+ "@[%a@;<1 2>%a@ \
25992599+ %a@;<1 2>%a\
25992600 @]"
26002600- txt1 type_path_expansion (trees_of_type_path_expansion tp)
26012601- txt3 type_path_expansion tp0
26012601+ pp_doc txt1 type_path_expansion (trees_of_type_path_expansion tp)
26022602+ pp_doc txt3 type_path_expansion tp0
26022603 | _ ->
26032604 fprintf ppf
26042604- "@[%t@;<1 2>@[<hv>%a@]\
26052605- @ %t@;<1 2>%a\
26052605+ "@[%a@;<1 2>@[<hv>%a@]\
26062606+ @ %a@;<1 2>%a\
26062607 @]"
26072607- txt2 type_path_list (List.map trees_of_type_path_expansion tpl)
26082608- txt3 type_path_expansion tp0)
26082608+ pp_doc txt2 type_path_list (List.map trees_of_type_path_expansion tpl)
26092609+ pp_doc txt3 type_path_expansion tp0)
2609261026102611(* Adapt functions to exposed interface *)
26112612let tree_of_path = tree_of_path None
···26152616let tree_of_type_declaration ident td rs =
26162617 with_hidden_items [{hide=true; ident}]
26172618 (fun () -> tree_of_type_declaration ident td rs)
26192619+26202620+(** Compatibility module for Format printers *)
26212621+module Compat = struct
26222622+ let longident = Fmt.compat longident
26232623+ let path = Fmt.compat path
26242624+ let type_expr = Fmt.compat type_expr
26252625+ let shared_type_scheme = Fmt.compat shared_type_scheme
26262626+ let signature = Fmt.compat signature
26272627+ let class_type = Fmt.compat class_type
26282628+ let modtype = Fmt.compat modtype
26292629+ let string_of_label = string_of_label
26302630+end
+51-48
typing/printtyp.mli
···15151616(* Printing functions *)
17171818-open Format
1818+open Format_doc
1919open Types
2020open Outcometree
21212222-val longident: formatter -> Longident.t -> unit
2323-val ident: formatter -> Ident.t -> unit
2222+val longident: Longident.t printer
2323+val ident: Ident.t printer
2424val namespaced_ident: Shape.Sig_component_kind.t -> Ident.t -> string
2525val tree_of_path: Path.t -> out_ident
2626-val path: formatter -> Path.t -> unit
2626+val path: Path.t printer
2727val string_of_path: Path.t -> string
28282929-val type_path: formatter -> Path.t -> unit
2929+val type_path: Path.t printer
3030(** Print a type path taking account of [-short-paths].
3131 Calls should be within [wrap_printing_env]. *)
3232···4646 (* This affects all the printing functions below *)
4747 (* Also, if [~error:true], then disable the loading of cmis *)
48484949-(** [wrap_printing_env_error env f] ensures that all printing functions in a
5050- [Location.error] report are evaluated within the [wrap_printing_env
5151- ~error:true env] context. (The original call to [f] is also evaluated
5252- within that context.)
5353- *)
5454-val wrap_printing_env_error :
5555- Env.t -> (unit -> Location.error) -> Location.error
5656-5749module Naming_context: sig
5850 val enable: bool -> unit
5951 (** When contextual names are enabled, the mapping between identifiers
···8072 collected up to this point, and reset the list of collected
8173 explanations *)
82748383- val print_located_explanations:
8484- Format.formatter -> explanation list -> unit
7575+ val print_located_explanations: explanation list printer
85768686- val err_msg: unit -> (Format.formatter -> unit) option
7777+ val err_msg: unit -> doc option
8778 (** [err_msg ()] return an error message if there are pending conflict
8879 explanations at this point. It is often important to check for conflicts
8980 after all printing is done, thus the delayed nature of [err_msg]*)
···9990 other type formatters such as [prepared_type_expr].) If you want multiple
10091 types to use common names for type variables, see [prepare_for_printing] and
10192 [prepared_type_expr]. *)
102102-val type_expr: formatter -> type_expr -> unit
9393+val type_expr: type_expr printer
1039410495(** [prepare_for_printing] resets the global printing environment, a la [reset],
10596 and prepares the types for printing by reserving names and marking loops.
···112103*)
113104val add_type_to_preparation: type_expr -> unit
114105115115-val prepared_type_expr: formatter -> type_expr -> unit
106106+val prepared_type_expr: type_expr printer
116107(** The function [prepared_type_expr] is a less-safe but more-flexible version
117108 of [type_expr] that should only be called on [type_expr]s that have been
118109 passed to [prepare_for_printing]. Unlike [type_expr], this function does no
···123114 [prepared_type_expr], they will use the same names for the same type
124115 variables. *)
125116126126-val constructor_arguments: formatter -> constructor_arguments -> unit
117117+val constructor_arguments: constructor_arguments printer
127118val tree_of_type_scheme: type_expr -> out_type
128128-val type_scheme: formatter -> type_expr -> unit
129129-val prepared_type_scheme: formatter -> type_expr -> unit
130130-val shared_type_scheme: formatter -> type_expr -> unit
119119+val type_scheme: type_expr printer
120120+val prepared_type_scheme: type_expr printer
121121+val shared_type_scheme: type_expr printer
131122(** [shared_type_scheme] is very similar to [type_scheme], but does not reset
132123 the printing context first. This is intended to be used in cases where the
133124 printing should have a particularly wide context, such as documentation
···135126 for which [type_scheme] is better suited. *)
136127137128val tree_of_value_description: Ident.t -> value_description -> out_sig_item
138138-val value_description: Ident.t -> formatter -> value_description -> unit
139139-val label : formatter -> label_declaration -> unit
129129+val value_description: Ident.t -> value_description printer
130130+val label : label_declaration printer
140131val add_constructor_to_preparation : constructor_declaration -> unit
141141-val prepared_constructor : formatter -> constructor_declaration -> unit
142142-val constructor : formatter -> constructor_declaration -> unit
132132+val prepared_constructor : constructor_declaration printer
133133+val constructor : constructor_declaration printer
143134val tree_of_type_declaration:
144135 Ident.t -> type_declaration -> rec_status -> out_sig_item
145136val add_type_declaration_to_preparation :
146137 Ident.t -> type_declaration -> unit
147147-val prepared_type_declaration: Ident.t -> formatter -> type_declaration -> unit
148148-val type_declaration: Ident.t -> formatter -> type_declaration -> unit
138138+val prepared_type_declaration: Ident.t -> type_declaration printer
139139+val type_declaration: Ident.t -> type_declaration printer
149140val tree_of_extension_constructor:
150141 Ident.t -> extension_constructor -> ext_status -> out_sig_item
151142val add_extension_constructor_to_preparation :
152143 extension_constructor -> unit
153144val prepared_extension_constructor:
154154- Ident.t -> formatter -> extension_constructor -> unit
145145+ Ident.t -> extension_constructor printer
155146val extension_constructor:
156156- Ident.t -> formatter -> extension_constructor -> unit
147147+ Ident.t -> extension_constructor printer
157148(* Prints extension constructor with the type signature:
158149 type ('a, 'b) bar += A of float
159150*)
160151161152val extension_only_constructor:
162162- Ident.t -> formatter -> extension_constructor -> unit
153153+ Ident.t -> extension_constructor printer
163154(* Prints only extension constructor without type signature:
164155 A of float
165156*)
166157167158val tree_of_module:
168159 Ident.t -> ?ellipsis:bool -> module_type -> rec_status -> out_sig_item
169169-val modtype: formatter -> module_type -> unit
170170-val signature: formatter -> signature -> unit
160160+val modtype: module_type printer
161161+val signature: signature printer
171162val tree_of_modtype: module_type -> out_module_type
172163val tree_of_modtype_declaration:
173164 Ident.t -> modtype_declaration -> out_sig_item
···183174 expect: (_: sig end) (Y:X.T) (_:sig end) (Z:X.T)
184175*)
185176val functor_parameters:
186186- sep:(Format.formatter -> unit -> unit) ->
187187- ('b -> Format.formatter -> unit) ->
188188- (Ident.t option * 'b) list -> Format.formatter -> unit
177177+ sep:unit printer -> ('b -> Format_doc.formatter -> unit) ->
178178+ (Ident.t option * 'b) list -> Format_doc.formatter -> unit
189179190180type type_or_scheme = Type | Type_scheme
191181192182val tree_of_signature: Types.signature -> out_sig_item list
193183val tree_of_typexp: type_or_scheme -> type_expr -> out_type
194194-val modtype_declaration: Ident.t -> formatter -> modtype_declaration -> unit
195195-val class_type: formatter -> class_type -> unit
184184+val modtype_declaration: Ident.t -> modtype_declaration printer
185185+val class_type: class_type printer
196186val tree_of_class_declaration:
197187 Ident.t -> class_declaration -> rec_status -> out_sig_item
198198-val class_declaration: Ident.t -> formatter -> class_declaration -> unit
188188+val class_declaration: Ident.t -> class_declaration printer
199189val tree_of_cltype_declaration:
200190 Ident.t -> class_type_declaration -> rec_status -> out_sig_item
201201-val cltype_declaration: Ident.t -> formatter -> class_type_declaration -> unit
191191+val cltype_declaration: Ident.t -> class_type_declaration printer
202192val type_expansion :
203203- type_or_scheme -> Format.formatter -> Errortrace.expanded_type -> unit
193193+ type_or_scheme -> Errortrace.expanded_type printer
204194val prepare_expansion: Errortrace.expanded_type -> Errortrace.expanded_type
195195+196196+module Compat: sig
197197+ (** {!Format} compatible printers *)
198198+ type 'a printer := Format.formatter -> 'a -> unit
199199+ val longident : Longident.t printer
200200+ val path: Path.t printer
201201+ val type_expr: type_expr printer
202202+ val shared_type_scheme: type_expr printer
203203+ val signature: signature printer
204204+ val modtype: module_type printer
205205+ val class_type: class_type printer
206206+ val string_of_label: Asttypes.arg_label -> string
207207+end
208208+205209val report_ambiguous_type_error:
206210 formatter -> Env.t -> (Path.t * Path.t) -> (Path.t * Path.t) list ->
207207- (formatter -> unit) -> (formatter -> unit) -> (formatter -> unit) -> unit
211211+ Format_doc.t -> Format_doc.t -> Format_doc.t -> unit
208212209213val report_unification_error :
210214 formatter ->
211215 Env.t -> Errortrace.unification_error ->
212212- ?type_expected_explanation:(formatter -> unit) ->
213213- (formatter -> unit) -> (formatter -> unit) ->
216216+ ?type_expected_explanation:Format_doc.t -> Format_doc.t -> Format_doc.t ->
214217 unit
215218216219val report_equality_error :
217220 formatter ->
218221 type_or_scheme ->
219222 Env.t -> Errortrace.equality_error ->
220220- (formatter -> unit) -> (formatter -> unit) ->
223223+ Format_doc.t -> Format_doc.t ->
221224 unit
222225223226val report_moregen_error :
224227 formatter ->
225228 type_or_scheme ->
226229 Env.t -> Errortrace.moregen_error ->
227227- (formatter -> unit) -> (formatter -> unit) ->
230230+ Format_doc.t -> Format_doc.t ->
228231 unit
229232230233val report_comparison_error :
231234 formatter ->
232235 type_or_scheme ->
233236 Env.t -> Errortrace.comparison_error ->
234234- (formatter -> unit) -> (formatter -> unit) ->
237237+ Format_doc.t -> Format_doc.t ->
235238 unit
236239237240module Subtype : sig
···253256254257(** [printed_signature sourcefile ppf sg] print the signature [sg] of
255258 [sourcefile] with potential warnings for name collisions *)
256256-val printed_signature: string -> formatter -> signature -> unit
259259+val printed_signature: string -> Format.formatter -> signature -> unit
···1919open Types
2020open Typecore
2121open Typetexp
2222-open Format
232224232524type 'a class_info = {
···48474948type 'a full_class = {
5049 id : Ident.t;
5151- id_loc : tag loc;
5050+ id_loc : string loc;
5251 clty: class_declaration;
5352 ty_id: Ident.t;
5453 cltydef: class_type_declaration;
···9493 | Bad_class_type_parameters of Ident.t * type_expr list * type_expr list
9594 | Class_match_failure of Ctype.class_match_failure list
9695 | Unbound_val of string
9797- | Unbound_type_var of (formatter -> unit) * Ctype.closed_class_failure
9696+ | Unbound_type_var of Format_doc.t * Ctype.closed_class_failure
9897 | Non_generalizable_class of
9998 { id : Ident.t
10099 ; clty : Types.class_declaration
···17431742 | Some reason ->
17441743 let printer =
17451744 if define_class
17461746- then function ppf -> Printtyp.class_declaration id ppf clty
17471747- else function ppf -> Printtyp.cltype_declaration id ppf cltydef
17451745+ then Format_doc.doc_printf "%a" (Printtyp.class_declaration id) clty
17461746+ else Format_doc.doc_printf "%a" (Printtyp.cltype_declaration id) cltydef
17481747 in
17491748 raise(Error(cl.pci_loc, env, Unbound_type_var(printer, reason)))
17501749 end;
···1980197919811980(* Error report *)
1982198119831983-open Format
19821982+open Format_doc
1984198319851984let non_virtual_string_of_kind : kind -> string = function
19861985 | Object -> "object"
···19881987 | Class_type -> "non-virtual class type"
1989198819901989module Style=Misc.Style
19901990+19911991+let out_type ppf t = Style.as_inline_code !Oprint.out_type ppf t
1991199219921993let report_error env ppf =
19931994 let pp_args ppf args =
···19981999 | Repeated_parameter ->
19992000 fprintf ppf "A type parameter occurs several times"
20002001 | Unconsistent_constraint err ->
20022002+ let msg = Format_doc.Core.msg in
20012003 fprintf ppf "@[<v>The class constraints are not consistent.@ ";
20022004 Printtyp.report_unification_error ppf env err
20032003- (fun ppf -> fprintf ppf "Type")
20042004- (fun ppf -> fprintf ppf "is not compatible with type");
20052005+ (msg "Type")
20062006+ (msg "is not compatible with type");
20052007 fprintf ppf "@]"
20062008 | Field_type_mismatch (k, m, err) ->
20092009+ let msg = Format_doc.doc_printf in
20072010 Printtyp.report_unification_error ppf env err
20082008- (function ppf ->
20092009- fprintf ppf "The %s %a@ has type" k Style.inline_code m)
20102010- (function ppf ->
20112011- fprintf ppf "but is expected to have type")
20112011+ (msg "The %s %a@ has type" k Style.inline_code m)
20122012+ (msg "but is expected to have type")
20122013 | Unexpected_field (ty, lab) ->
20132014 fprintf ppf
20142015 "@[@[<2>This object is expected to have type :@ %a@]\
···20462047 Printtyp.prepare_for_printing [abbrev; actual; expected];
20472048 fprintf ppf "@[The abbreviation@ %a@ expands to type@ %a@ \
20482049 but is used with type@ %a@]"
20492049- (Style.as_inline_code !Oprint.out_type)
20502050- (Printtyp.tree_of_typexp Type abbrev)
20512051- (Style.as_inline_code !Oprint.out_type)
20522052- (Printtyp.tree_of_typexp Type actual)
20532053- (Style.as_inline_code !Oprint.out_type)
20542054- (Printtyp.tree_of_typexp Type expected)
20502050+ out_type (Printtyp.tree_of_typexp Type abbrev)
20512051+ out_type (Printtyp.tree_of_typexp Type actual)
20522052+ out_type (Printtyp.tree_of_typexp Type expected)
20552053 | Constructor_type_mismatch (c, err) ->
20542054+ let msg = Format_doc.doc_printf in
20562055 Printtyp.report_unification_error ppf env err
20572057- (function ppf ->
20582058- fprintf ppf "The expression %a has type"
20562056+ (msg "The expression %a has type"
20592057 Style.inline_code ("new " ^ c)
20602058 )
20612061- (function ppf ->
20622062- fprintf ppf "but is used with type")
20592059+ (msg "but is used with type")
20632060 | Virtual_class (kind, mets, vals) ->
20642061 let kind = non_virtual_string_of_kind kind in
20652062 let missings =
···20852082 but is here applied to %i type argument(s)@]"
20862083 (Style.as_inline_code Printtyp.longident) lid expected provided
20872084 | Parameter_mismatch err ->
20852085+ let msg = Format_doc.Core.msg in
20882086 Printtyp.report_unification_error ppf env err
20892089- (function ppf ->
20902090- fprintf ppf "The type parameter")
20912091- (function ppf ->
20922092- fprintf ppf "does not meet its constraint: it should be")
20872087+ (msg "The type parameter")
20882088+ (msg "does not meet its constraint: it should be")
20932089 | Bad_parameters (id, params, cstrs) ->
20942090 Printtyp.prepare_for_printing (params @ cstrs);
20952091 fprintf ppf
···21122108 Includeclass.report_error Type ppf error
21132109 | Unbound_val lab ->
21142110 fprintf ppf "Unbound instance variable %a" Style.inline_code lab
21152115- | Unbound_type_var (printer, reason) ->
21112111+ | Unbound_type_var (msg, reason) ->
21162112 let print_reason ppf { Ctype.free_variable; meth; meth_ty; } =
21172113 let (ty0, kind) = free_variable in
21182114 let ty1 =
···21222118 in
21232119 Printtyp.add_type_to_preparation meth_ty;
21242120 Printtyp.add_type_to_preparation ty1;
21252125- let pp_type ppf ty = Style.as_inline_code !Oprint.out_type ppf ty in
21262121 fprintf ppf
21272122 "The method %a@ has type@;<1 2>%a@ where@ %a@ is unbound"
21282123 Style.inline_code meth
21292129- pp_type (Printtyp.tree_of_typexp Type meth_ty)
21302130- pp_type (Printtyp.tree_of_typexp Type ty0)
21242124+ out_type (Printtyp.tree_of_typexp Type meth_ty)
21252125+ out_type (Printtyp.tree_of_typexp Type ty0)
21312126 in
21322127 fprintf ppf
21332133- "@[<v>@[Some type variables are unbound in this type:@;<1 2>%t@]@ \
21282128+ "@[<v>@[Some type variables are unbound in this type:@;<1 2>%a@]@ \
21342129 @[%a@]@]"
21352135- printer print_reason reason
21302130+ pp_doc msg print_reason reason
21362131 | Non_generalizable_class {id; clty; nongen_vars } ->
21372132 let[@manual.ref "ss:valuerestriction"] manual_ref = [ 6; 1; 2] in
21382133 Printtyp.prepare_for_printing nongen_vars;
···21522147 Some occurrences are contravariant@]"
21532148 (Style.as_inline_code Printtyp.type_scheme) ty
21542149 | Non_collapsable_conjunction (id, clty, err) ->
21502150+ let msg = Format_doc.Core.msg in
21552151 fprintf ppf
21562152 "@[The type of this class,@ %a,@ \
21572153 contains non-collapsible conjunctive types in constraints.@ %t@]"
21582154 (Style.as_inline_code @@ Printtyp.class_declaration id) clty
21592155 (fun ppf -> Printtyp.report_unification_error ppf env err
21602160- (fun ppf -> fprintf ppf "Type")
21612161- (fun ppf -> fprintf ppf "is not compatible with type")
21562156+ (msg "Type")
21572157+ (msg "is not compatible with type")
21622158 )
21632159 | Self_clash err ->
21602160+ let msg = Format_doc.Core.msg in
21642161 Printtyp.report_unification_error ppf env err
21652165- (function ppf ->
21662166- fprintf ppf "This object is expected to have type")
21672167- (function ppf ->
21682168- fprintf ppf "but actually has type")
21622162+ (msg "This object is expected to have type")
21632163+ (msg "but actually has type")
21692164 | Mutability_mismatch (_lab, mut) ->
21702165 let mut1, mut2 =
21712166 if mut = Immutable then "mutable", "immutable"
+2-4
typing/typeclass.mli
···15151616open Asttypes
1717open Types
1818-open Format
1919-2018type 'a class_info = {
2119 cls_id : Ident.t;
2220 cls_id_loc : string loc;
···111109 | Bad_class_type_parameters of Ident.t * type_expr list * type_expr list
112110 | Class_match_failure of Ctype.class_match_failure list
113111 | Unbound_val of string
114114- | Unbound_type_var of (formatter -> unit) * Ctype.closed_class_failure
112112+ | Unbound_type_var of Format_doc.t * Ctype.closed_class_failure
115113 | Non_generalizable_class of
116114 { id : Ident.t
117115 ; clty : Types.class_declaration
···129127exception Error of Location.t * Env.t * error
130128exception Error_forward of Location.error
131129132132-val report_error : Env.t -> formatter -> error -> unit
130130+val report_error : Env.t -> error Format_doc.printer
133131134132(* Forward decl filled in by Typemod.type_open_descr *)
135133val type_open_descr :
+71-82
typing/typecore.ml
···201201 | Wrong_expected_kind of wrong_kind_sort * wrong_kind_context * type_expr
202202 | Expr_not_a_record_type of type_expr
203203204204+205205+let not_principal fmt =
206206+ Format_doc.Core.kmsg (fun x -> Warnings.Not_principal x) fmt
207207+204208exception Error of Location.t * Env.t * error
205209exception Error_forward of Location.error
206210···947951 generalize_structure t2;
948952 if not (fully_generic t1 && fully_generic t2) then
949953 let msg =
950950- Format.asprintf
954954+ Format_doc.doc_printf
951955 "typing this pattern requires considering@ %a@ and@ %a@ as \
952956 equal.@,\
953957 But the knowledge of these types"
···11641168 let paths = ambiguous_types env lbl rest in
11651169 let expansion = match Printtyp.Conflicts.err_msg () with
11661170 | None -> ""
11671167- | Some msg -> Format.asprintf "%t" msg
11711171+ | Some msg -> Format_doc.(asprintf "%a" pp_doc) msg
11681172 in
11691173 if paths <> [] then
11701174 warn lid.loc
···11761180 let warn_non_principal warn lid =
11771181 let name = Datatype_kind.label_name kind in
11781182 warn lid.loc
11791179- (Warnings.Not_principal
11801180- ("this type-based " ^ name ^ " disambiguation"))
11831183+ (not_principal "this type-based %s disambiguation" name)
1181118411821185 (* we selected a name out of the lexical scope *)
11831186 let warn_out_of_scope warn lid env tpath =
11841187 if Warnings.is_active (Name_out_of_scope ("",[],false)) then begin
11851188 let path_s =
11861189 Printtyp.wrap_printing_env ~error:true env
11871187- (fun () -> Format.asprintf "%a" Printtyp.type_path tpath) in
11901190+ (fun () -> Format_doc.asprintf "%a" Printtyp.type_path tpath) in
11881191 warn lid.loc
11891192 (Warnings.Name_out_of_scope (path_s, [Longident.last lid.txt], false))
11901193 end
···14241427 in
14251428 if !w_pr then
14261429 Location.prerr_warning loc
14271427- (Warnings.Not_principal "this type-based record disambiguation")
14301430+ (not_principal "this type-based record disambiguation")
14281431 else begin
14291432 match List.rev !w_amb with
14301433 (_,types,ex)::_ as amb ->
···33643367 | Tconstr(path, _, _) when Path.same path fmt6_path ->
33653368 if !Clflags.principal && get_level ty_exp <> generic_level then
33663369 Location.prerr_warning loc
33673367- (Warnings.Not_principal "this coercion to format6");
33703370+ (not_principal "this coercion to format6");
33683371 true
33693372 | _ -> false
33703373 in
···39963999 | Tpoly (ty, tl) ->
39974000 if !Clflags.principal && get_level typ <> generic_level then
39984001 Location.prerr_warning loc
39993999- (Warnings.Not_principal "this use of a polymorphic method");
40024002+ (not_principal "this use of a polymorphic method");
40004003 snd (instance_poly ~fixed:false tl ty)
40014004 | Tvar _ ->
40024005 let ty' = newvar () in
···42634266 < Btype.generic_level
42644267 then
42654268 Location.prerr_warning loc
42664266- (Warnings.Not_principal "this module packing");
42694269+ (not_principal "this module packing");
42674270 (p, fl)
42684271 | Tvar _ ->
42694272 raise (Error (loc, env, Cannot_infer_signature))
···44564459 force (); force' ();
44574460 if not gen && !Clflags.principal then
44584461 Location.prerr_warning loc
44594459- (Warnings.Not_principal "this ground coercion");
44624462+ (not_principal "this ground coercion");
44604463 with Subtype err ->
44614464 (* prerr_endline "coercion failed"; *)
44624465 raise (Error (loc, env, Not_subtype err))
···54265429 (fun () -> type_argument env sarg ty ty0)
54275430 else begin
54285431 may_warn sarg.pexp_loc
54295429- (Warnings.Not_principal "using an optional argument here");
54325432+ (not_principal "using an optional argument here");
54305433 (fun () -> option_some env (type_argument env sarg
54315434 (extract_option_type env ty)
54325435 (extract_option_type env ty0)))
···54655468 | Some (l', sarg, commuted, remaining_sargs) ->
54665469 if commuted then begin
54675470 may_warn sarg.pexp_loc
54685468- (Warnings.Not_principal "commuting this argument")
54715471+ (not_principal "commuting this argument")
54695472 end;
54705473 if not optional && is_optional l' then
54715474 Location.prerr_warning sarg.pexp_loc
···64666469let spellcheck_idents ppf unbound valid_idents =
64676470 spellcheck ppf (Ident.name unbound) (List.map Ident.name valid_idents)
6468647164696469-open Format
64726472+open Format_doc
64736473+module Fmt = Format_doc
6470647464716475let longident = Printtyp.longident
64726476···64966500 Some '.'
64976501 else None
64986502 in
64996499- let pp_const ppf (c,s) = Format.fprintf ppf "%s%c" c s in
65036503+ let pp_const ppf (c,s) = Fmt.fprintf ppf "%s%c" c s in
65006504 match const_str, suffix with
65016505 | Some c, Some s -> [
65026506 Location.msg
···65366540 | Some (Ppat_constant const) -> report_literal_type_constraint const diff
65376541 | _ -> []
6538654265396539-let report_type_expected_explanation expl ppf =
65406540- let because expl_str = fprintf ppf "@ because it is in %s" expl_str in
65436543+let report_type_expected_explanation expl =
65446544+ let because expl_str = doc_printf "@ because it is in %s" expl_str in
65416545 match expl with
65426546 | If_conditional ->
65436547 because "the condition of an if-statement"
···65606564 | When_guard ->
65616565 because "a when-guard"
6562656665636563-let report_type_expected_explanation_opt expl ppf =
65676567+let report_type_expected_explanation_opt expl =
65646568 match expl with
65656565- | None -> ()
65666566- | Some expl -> report_type_expected_explanation expl ppf
65696569+ | None -> Format_doc.empty
65706570+ | Some expl -> report_type_expected_explanation expl
6567657165686572let report_unification_error ~loc ?sub env err
65696573 ?type_expected_explanation txt1 txt2 =
···65736577 ) ()
6574657865756579let report_this_function ppf funct =
65766576- if Typedtree.exp_is_nominal funct then
65776577- let pexp = Untypeast.untype_expression funct in
65786578- Format.fprintf ppf "The function %a"
65796579- (Style.as_inline_code Pprintast.expression) pexp
65806580- else Format.fprintf ppf "This function"
65806580+ match Typedtree.nominal_exp_doc Printtyp.longident funct with
65816581+ | None -> Fmt.fprintf ppf "This function"
65826582+ | Some name ->
65836583+ Fmt.fprintf ppf "The function %a"
65846584+ (Style.as_inline_code Fmt.pp_doc) name
6581658565826586let report_too_many_arg_error ~funct ~func_ty ~previous_arg_loc
65836587 ~extra_arg_loc ~returns_unit loc =
···66096613 @ It is applied to too many arguments@]"
66106614 report_this_function funct Printtyp.type_expr func_ty
6611661566166616+let msg = Fmt.doc_printf
66176617+66126618let report_error ~loc env = function
66136619 | Constructor_arity_mismatch(lid, expected, provided) ->
66146620 Location.errorf ~loc
···66176623 (Style.as_inline_code longident) lid expected provided
66186624 | Label_mismatch(lid, err) ->
66196625 report_unification_error ~loc env err
66206620- (function ppf ->
66216621- fprintf ppf "The record field %a@ belongs to the type"
66266626+ (msg "The record field %a@ belongs to the type"
66226627 (Style.as_inline_code longident) lid)
66236623- (function ppf ->
66246624- fprintf ppf "but is mixed here with fields of type")
66286628+ (msg "but is mixed here with fields of type")
66256629 | Pattern_type_clash (err, pat) ->
66266630 let diff = type_clash_of_trace err.trace in
66276631 let sub = report_pattern_type_clash_hints pat diff in
66286632 report_unification_error ~loc ~sub env err
66296629- (function ppf ->
66306630- fprintf ppf "This pattern matches values of type")
66316631- (function ppf ->
66326632- fprintf ppf "but a pattern was expected which matches values of \
66336633- type");
66336633+ (msg "This pattern matches values of type")
66346634+ (msg "but a pattern was expected which matches values of type");
66346635 | Or_pattern_type_clash (id, err) ->
66356636 report_unification_error ~loc env err
66366636- (function ppf ->
66376637- fprintf ppf "The variable %a on the left-hand side of this \
66376637+ (msg "The variable %a on the left-hand side of this \
66386638 or-pattern has type" Style.inline_code (Ident.name id))
66396639- (function ppf ->
66406640- fprintf ppf "but on the right-hand side it has type")
66396639+ (msg "but on the right-hand side it has type")
66416640 | Multiply_bound_variable name ->
66426641 Location.errorf ~loc
66436642 "Variable %a is bound several times in this matching"
···66576656 report_unification_error ~loc ~sub env err
66586657 ~type_expected_explanation:
66596658 (report_type_expected_explanation_opt explanation)
66606660- (function ppf ->
66616661- fprintf ppf "This expression has type")
66626662- (function ppf ->
66636663- fprintf ppf "but an expression was expected of type");
66596659+ (msg "This expression has type")
66606660+ (msg "but an expression was expected of type");
66646661 | Function_arity_type_clash {
66656662 syntactic_arity; type_constraint; trace = { trace };
66666663 } ->
···67596756 (Style.as_inline_code Printtyp.type_path) type_path;
67606757 end else begin
67616758 fprintf ppf
67626762- "@[@[<2>%s type@ %a%t@]@ \
67596759+ "@[@[<2>%s type@ %a%a@]@ \
67636760 There is no %s %a within type %a@]"
67646761 eorp (Style.as_inline_code Printtyp.type_expr) ty
67656765- (report_type_expected_explanation_opt explanation)
67626762+ pp_doc (report_type_expected_explanation_opt explanation)
67666763 (Datatype_kind.label_name kind)
67676764 Style.inline_code name.txt
67686765 (Style.as_inline_code Printtyp.type_path) type_path;
···67746771 let name = Datatype_kind.label_name kind in
67756772 Location.error_of_printer ~loc (fun ppf () ->
67766773 Printtyp.report_ambiguous_type_error ppf env tp tpl
67776777- (function ppf ->
67786778- fprintf ppf "The %s %a@ belongs to the %s type"
67746774+ (msg "The %s %a@ belongs to the %s type"
67796775 name (Style.as_inline_code longident) lid
67806776 type_name)
67816781- (function ppf ->
67826782- fprintf ppf "The %s %a@ belongs to one of the following %s types:"
67776777+ (msg "The %s %a@ belongs to one of the following %s types:"
67836778 name (Style.as_inline_code longident) lid type_name)
67846784- (function ppf ->
67856785- fprintf ppf "but a %s was expected belonging to the %s type"
67796779+ (msg "but a %s was expected belonging to the %s type"
67866780 name type_name)
67876787- ) ()
67816781+ ) ()
67886782 | Invalid_format msg ->
67896783 Location.errorf ~loc "%s" msg
67906784 | Not_an_object (ty, explanation) ->
···67926786 fprintf ppf "This expression is not an object;@ \
67936787 it has type %a"
67946788 (Style.as_inline_code Printtyp.type_expr) ty;
67956795- report_type_expected_explanation_opt explanation ppf
67896789+ pp_doc ppf @@ report_type_expected_explanation_opt explanation
67966790 ) ()
67976791 | Undefined_method (ty, me, valid_methods) ->
67986792 Location.error_of_printer ~loc (fun ppf () ->
···68366830 Style.inline_code v
68376831 | Coercion_failure (ty_exp, err, b) ->
68386832 Location.error_of_printer ~loc (fun ppf () ->
68336833+ let intro =
68346834+ let ty_exp = Printtyp.prepare_expansion ty_exp in
68356835+ doc_printf "This expression cannot be coerced to type@;<1 2>%a;@ \
68366836+ it has type"
68376837+ (Style.as_inline_code @@ Printtyp.type_expansion Type) ty_exp
68386838+ in
68396839 Printtyp.report_unification_error ppf env err
68406840- (function ppf ->
68416841- let ty_exp = Printtyp.prepare_expansion ty_exp in
68426842- fprintf ppf "This expression cannot be coerced to type@;<1 2>%a;@ \
68436843- it has type"
68446844- (Style.as_inline_code @@ Printtyp.type_expansion Type) ty_exp)
68456845- (function ppf ->
68466846- fprintf ppf "but is here used with type");
68406840+ intro
68416841+ (Fmt.doc_printf "but is here used with type");
68476842 if b then
68486843 fprintf ppf
68496844 ".@.@[<hov>This simple coercion was not fully general.@ \
···68546849 | Not_a_function (ty, explanation) ->
68556850 Location.errorf ~loc
68566851 "This expression should not be a function,@ \
68576857- the expected type is@ %a%t"
68526852+ the expected type is@ %a%a"
68586853 (Style.as_inline_code Printtyp.type_expr) ty
68596859- (report_type_expected_explanation_opt explanation)
68546854+ pp_doc (report_type_expected_explanation_opt explanation)
68606855 | Too_many_arguments (ty, explanation) ->
68616856 Location.errorf ~loc
68626857 "This function expects too many arguments,@ \
68636863- it should have type@ %a%t"
68586858+ it should have type@ %a%a"
68646859 (Style.as_inline_code Printtyp.type_expr) ty
68656865- (report_type_expected_explanation_opt explanation)
68606860+ pp_doc (report_type_expected_explanation_opt explanation)
68666861 | Abstract_wrong_label {got; expected; expected_type; explanation} ->
68676862 let label ~long ppf = function
68686863 | Nolabel -> fprintf ppf "unlabeled"
···68776872 | _ -> false
68786873 in
68796874 Location.errorf ~loc
68806880- "@[<v>@[<2>This function should have type@ %a%t@]@,\
68756875+ "@[<v>@[<2>This function should have type@ %a%a@]@,\
68816876 @[but its first argument is %a@ instead of %s%a@]@]"
68826877 (Style.as_inline_code Printtyp.type_expr) expected_type
68836883- (report_type_expected_explanation_opt explanation)
68786878+ pp_doc (report_type_expected_explanation_opt explanation)
68846879 (label ~long:true) got
68856880 (if second_long then "being " else "")
68866881 (label ~long:second_long) expected
···69136908 This is only allowed when the real type is known."
69146909 | Less_general (kind, err) ->
69156910 report_unification_error ~loc env err
69166916- (fun ppf -> fprintf ppf "This %s has type" kind)
69176917- (fun ppf -> fprintf ppf "which is less general than")
69116911+ (Fmt.doc_printf "This %s has type" kind)
69126912+ (Fmt.doc_printf "which is less general than")
69186913 | Modules_not_allowed ->
69196914 Location.errorf ~loc "Modules are not allowed in this pattern."
69206915 | Cannot_infer_signature ->
···69846979 "@[%s@ %s@ @[%a@]@]"
69856980 "This match case could not be refuted."
69866981 "Here is an example of a value that would reach it:"
69876987- (Style.as_inline_code Printpat.pretty_val) pat
69826982+ (Style.as_inline_code Printpat.top_pretty) pat
69886983 | Invalid_extension_constructor_payload ->
69896984 Location.errorf ~loc
69906985 "Invalid %a payload, a constructor is expected."
···70147009 "This kind of recursive class expression is not allowed"
70157010 | Letop_type_clash(name, err) ->
70167011 report_unification_error ~loc env err
70177017- (function ppf ->
70187018- fprintf ppf "The operator %a has type" Style.inline_code name)
70197019- (function ppf ->
70207020- fprintf ppf "but it was expected to have type")
70127012+ (msg "The operator %a has type" Style.inline_code name)
70137013+ (msg "but it was expected to have type")
70217014 | Andop_type_clash(name, err) ->
70227015 report_unification_error ~loc env err
70237023- (function ppf ->
70247024- fprintf ppf "The operator %a has type" Style.inline_code name)
70257025- (function ppf ->
70267026- fprintf ppf "but it was expected to have type")
70167016+ (msg "The operator %a has type" Style.inline_code name)
70177017+ (msg "but it was expected to have type")
70277018 | Bindings_type_clash(err) ->
70287019 report_unification_error ~loc env err
70297029- (function ppf ->
70307030- fprintf ppf "These bindings have type")
70317031- (function ppf ->
70327032- fprintf ppf "but bindings were expected of type")
70207020+ (Fmt.doc_printf "These bindings have type")
70217021+ (Fmt.doc_printf "but bindings were expected of type")
70337022 | Unbound_existential (ids, ty) ->
70347023 let pp_ident ppf id = pp_print_string ppf (Ident.name id) in
70357024 let pp_type ppf (ids,ty)=
···70767065 in
70777066 Location.errorf ~loc
70787067 "This %s should not be a %s,@ \
70797079- the expected type is@ %a%t"
70687068+ the expected type is@ %a%a"
70807069 ctx sort (Style.as_inline_code Printtyp.type_expr) ty
70817081- (report_type_expected_explanation_opt explanation)
70707070+ pp_doc (report_type_expected_explanation_opt explanation)
70827071 | Expr_not_a_record_type ty ->
70837072 Location.errorf ~loc
70847073 "This expression has type %a@ \
···70867075 (Style.as_inline_code Printtyp.type_expr) ty
7087707670887077let report_error ~loc env err =
70897089- Printtyp.wrap_printing_env_error env
70787078+ Printtyp.wrap_printing_env ~error:true env
70907079 (fun () -> report_error ~loc env err)
7091708070927081let () =
+24-24
typing/typedecl.ml
···1906190619071907(**** Error report ****)
1908190819091909-open Format
19091909+open Format_doc
19101910module Style = Misc.Style
1911191119121912let explain_unbound_gen ppf tv tl typ kwd pr =
···19781978 List.iter Printtyp.add_type_to_preparation [ty1; ty2]
19791979 ) path
1980198019811981+ module Fmt = Format_doc
19821982+19811983 let pp ppf reaching_path =
19821984 let pp_step ppf = function
19831985 | Expands_to (ty, body) ->
19841984- Format.fprintf ppf "%a = %a"
19861986+ Fmt.fprintf ppf "%a = %a"
19851987 (Style.as_inline_code Printtyp.prepared_type_expr) ty
19861988 (Style.as_inline_code Printtyp.prepared_type_expr) body
19871989 | Contains (outer, inner) ->
19881988- Format.fprintf ppf "%a contains %a"
19901990+ Fmt.fprintf ppf "%a contains %a"
19891991 (Style.as_inline_code Printtyp.prepared_type_expr) outer
19901992 (Style.as_inline_code Printtyp.prepared_type_expr) inner
19911993 in
19921992- let comma ppf () = Format.fprintf ppf ",@ " in
19931993- Format.(pp_print_list ~pp_sep:comma pp_step) ppf reaching_path
19941994+ Fmt.(pp_print_list ~pp_sep:comma) pp_step ppf reaching_path
1994199519951996 let pp_colon ppf path =
19961996- Format.fprintf ppf ":@;<1 2>@[<v>%a@]"
19971997- pp path
19971997+ Fmt.fprintf ppf ":@;<1 2>@[<v>%a@]" pp path
19981998end
1999199920002000+let quoted_type ppf ty = Style.as_inline_code !Oprint.out_type ppf ty
20002001let report_error ppf = function
20012002 | Repeated_parameter ->
20022003 fprintf ppf "A type parameter occurs several times"
···20362037 "the original" "this" "definition" env)
20372038 err
20382039 | Constraint_failed (env, err) ->
20402040+ let msg = Format_doc.Core.msg in
20392041 fprintf ppf "@[<v>Constraints are not satisfied in this type.@ ";
20402042 Printtyp.report_unification_error ppf env err
20412041- (fun ppf -> fprintf ppf "Type")
20422042- (fun ppf -> fprintf ppf "should be an instance of");
20432043+ (msg "Type")
20442044+ (msg "should be an instance of");
20432045 fprintf ppf "@]"
20442046 | Non_regular { definition; used_as; defined_as; reaching_path } ->
20452047 let reaching_path = Reaching_path.simplify reaching_path in
20462046- let pp_type ppf ty = Style.as_inline_code !Oprint.out_type ppf ty in
20472048 Printtyp.prepare_for_printing [used_as; defined_as];
20482049 Reaching_path.add_to_preparation reaching_path;
20492050 fprintf ppf
···20532054 All uses need to match the definition for the recursive type \
20542055 to be regular.@]"
20552056 Style.inline_code (Path.name definition)
20562056- pp_type (Printtyp.tree_of_typexp Type defined_as)
20572057- pp_type (Printtyp.tree_of_typexp Type used_as)
20572057+ quoted_type (Printtyp.tree_of_typexp Type defined_as)
20582058+ quoted_type (Printtyp.tree_of_typexp Type used_as)
20582059 (fun pp ->
20592060 let is_expansion = function Expands_to _ -> true | _ -> false in
20602061 if List.exists is_expansion reaching_path then
···20622063 Reaching_path.pp_colon reaching_path
20632064 else fprintf pp ".@ ")
20642065 | Inconsistent_constraint (env, err) ->
20662066+ let msg = Format_doc.Core.msg in
20652067 fprintf ppf "@[<v>The type constraints are not consistent.@ ";
20662068 Printtyp.report_unification_error ppf env err
20672067- (fun ppf -> fprintf ppf "Type")
20682068- (fun ppf -> fprintf ppf "is not compatible with type");
20692069+ (msg "Type")
20702070+ (msg "is not compatible with type");
20692071 fprintf ppf "@]"
20702072 | Type_clash (env, err) ->
20732073+ let msg = Format_doc.Core.msg in
20712074 Printtyp.report_unification_error ppf env err
20722072- (function ppf ->
20732073- fprintf ppf "This type constructor expands to type")
20742074- (function ppf ->
20752075- fprintf ppf "but is used here with type")
20752075+ (msg "This type constructor expands to type")
20762076+ (msg "but is used here with type")
20762077 | Null_arity_external ->
20772078 fprintf ppf "External identifiers must be functions"
20782079 | Missing_native_external ->
···21212122 "the type" "this extension" "definition" env)
21222123 err
21232124 | Rebind_wrong_type (lid, env, err) ->
21252125+ let msg = Format_doc.doc_printf in
21242126 Printtyp.report_unification_error ppf env err
21252125- (function ppf ->
21262126- fprintf ppf "The constructor %a@ has type"
21272127+ (msg "The constructor %a@ has type"
21272128 (Style.as_inline_code Printtyp.longident) lid)
21282128- (function ppf ->
21292129- fprintf ppf "but was expected to be of type")
21292129+ (msg "but was expected to be of type")
21302130 | Rebind_mismatch (lid, p, p') ->
21312131 fprintf ppf
21322132 "@[%s@ %a@ %s@ %a@ %s@ %s@ %a@]"
···22562256 fprintf ppf "an unnamed existential variable"
22572257 | Some str ->
22582258 fprintf ppf "the existential variable %a"
22592259- (Style.as_inline_code Pprintast.tyvar) str in
22592259+ (Style.as_inline_code Pprintast.Doc.tyvar) str in
22602260 fprintf ppf "@[This type cannot be unboxed because@ \
22612261 it might contain both float and non-float values,@ \
22622262 depending on the instantiation of %a.@ \
···22712271 Style.inline_code "nonrec"
22722272 | Invalid_private_row_declaration ty ->
22732273 let pp_private ppf ty = fprintf ppf "private %a" Printtyp.type_expr ty in
22742274- Format.fprintf ppf
22742274+ fprintf ppf
22752275 "@[<hv>This private row type declaration is invalid.@ \
22762276 The type expression on the right-hand side reduces to@;<1 2>%a@ \
22772277 which does not have a free row type variable.@]@,\
+1-3
typing/typedecl.mli
···1616(* Typing of type definitions and primitive definitions *)
17171818open Types
1919-open Format
2020-2119val transl_type_decl:
2220 Env.t -> Asttypes.rec_flag -> Parsetree.type_declaration list ->
2321 Typedtree.type_declaration list * Env.t * Shape.t list
···111109112110exception Error of Location.t * error
113111114114-val report_error: formatter -> error -> unit
112112+val report_error: error Format_doc.printer
+28-10
typing/typedtree.ml
···899899 if they satisfy one of:
900900 - Similar to an identifier: words separated by '.' or '#'.
901901 - Do not contain spaces when printed.
902902- *)
903903-let rec exp_is_nominal exp =
904904- match exp.exp_desc with
905905- | _ when exp.exp_attributes <> [] -> false
906906- | Texp_ident _ | Texp_instvar _ | Texp_constant _
907907- | Texp_variant (_, None)
908908- | Texp_construct (_, _, []) ->
909909- true
910910- | Texp_field (parent, _, _) | Texp_send (parent, _) -> exp_is_nominal parent
911911- | _ -> false
902902+*)
903903+let nominal_exp_doc lid t =
904904+ let longident l = Format_doc.core lid l.Location.txt in
905905+ let rec nominal_exp_doc doc exp =
906906+ match exp.exp_desc with
907907+ | _ when exp.exp_attributes <> [] -> None
908908+ | Texp_ident (_,l,_) ->
909909+ Some (longident l doc)
910910+ | Texp_instvar (_,_,s) ->
911911+ Some (Format_doc.Core.string s.Location.txt doc)
912912+ | Texp_constant _ -> assert false
913913+ | Texp_variant (lbl, None) ->
914914+ Some (Format_doc.Core.printf "`%s" lbl doc)
915915+ | Texp_construct (l, _, []) -> Some (longident l doc)
916916+ | Texp_field (parent, lbl, _) ->
917917+ Option.map
918918+ (Format_doc.Core.printf ".%t" (longident lbl))
919919+ (nominal_exp_doc doc parent)
920920+ | Texp_send (parent, meth) ->
921921+ let name = match meth with
922922+ | Tmeth_name name -> name
923923+ | Tmeth_val id | Tmeth_ancestor (id,_) -> Ident.name id in
924924+ Option.map
925925+ (Format_doc.Core.printf "#%s" name)
926926+ (nominal_exp_doc doc parent)
927927+ | _ -> None
928928+ in
929929+ nominal_exp_doc Format_doc.empty t
+5-3
typing/typedtree.mli
···920920val split_pattern:
921921 computation general_pattern -> pattern option * pattern option
922922923923-(** Whether an expression looks nice as the subject of a sentence in a error
924924- message. *)
925925-val exp_is_nominal : expression -> bool
923923+(** Returns a format document if the expression reads nicely as the subject of a
924924+ sentence in a error message. *)
925925+val nominal_exp_doc :
926926+ Longident.t Format_doc.printer -> expression
927927+ -> Format_doc.t option
+18-19
typing/typemod.ml
···1919open Asttypes
2020open Parsetree
2121open Types
2222-open Format
2222+open Format_doc
23232424module Style = Misc.Style
2525···21192119 in
21202120 Result.Error (Errortrace.Package_coercion msg)
21212121 | exception Includemod.Error e ->
21222122- let msg = Includemod_errorprinter.err_msgs e in
21222122+ let msg = doc_printf "%a" Includemod_errorprinter.err_msgs e in
21232123 Result.Error (Errortrace.Package_inclusion msg)
2124212421252125let () = Ctype.package_subtype := package_subtype
···21812181 | true , _ -> Includemod.Error.Empty_struct, mty
21822182 | false, Some p -> Includemod.Error.Named p, mty
21832183 | false, None -> Includemod.Error.Anonymous, mty
21842184+21852185+let not_principal msg = Warnings.Not_principal (Format_doc.Core.msg msg)
2184218621852187let rec type_module ?(alias=false) sttn funct_body anchor env smod =
21862188 Builtin_attributes.warning_scope smod.pmod_attributes
···23082310 not (Typecore.generalizable (Btype.generic_level-1) exp.exp_type)
23092311 then
23102312 Location.prerr_warning smod.pmod_loc
23112311- (Warnings.Not_principal "this module unpacking");
23132313+ (not_principal "this module unpacking");
23122314 modtype_of_package env smod.pmod_loc p fl
23132315 | Tvar _ ->
23142316 raise (Typecore.Error
···30973099 Typecore.force_delayed_checks ();
30983100 let shape = Shape_reduce.local_reduce Env.empty shape in
30993101 Printtyp.wrap_printing_env ~error:false initial_env
31003100- (fun () -> fprintf std_formatter "%a@."
31023102+ Format.(fun () -> fprintf std_formatter "%a@."
31013103 (Printtyp.printed_signature @@ Unit_info.source_file target)
31023104 simple_sg
31033105 );
···32913293 "@[This module is not a functor; it has type@ %a@]"
32923294 (Style.as_inline_code modtype) mty
32933295 | Not_included errs ->
32943294- let main = Includemod_errorprinter.err_msgs errs in
32953295- let footnote = Printtyp.Conflicts.err_msg in
32963296- Location.errorf ~loc ~footnote "@[<v>Signature mismatch:@ %t@]" main
32963296+ Location.errorf ~loc ~footnote:Printtyp.Conflicts.err_msg
32973297+ "@[<v>Signature mismatch:@ %a@]"
32983298+ Includemod_errorprinter.err_msgs errs
32973299 | Cannot_eliminate_dependency mty ->
32983300 Location.errorf ~loc
32993301 "@[This functor has type@ %a@ \
···33123314 Style.inline_code "with"
33133315 (Style.as_inline_code longident) lid
33143316 | With_mismatch(lid, explanation) ->
33153315- let main = Includemod_errorprinter.err_msgs explanation in
33163316- let footnote = Printtyp.Conflicts.err_msg in
33173317- Location.errorf ~loc ~footnote
33173317+ Location.errorf ~loc ~footnote:Printtyp.Conflicts.err_msg
33183318 "@[<v>\
33193319 @[In this %a constraint, the new definition of %a@ \
33203320 does not match its original definition@ \
33213321 in the constrained signature:@]@ \
33223322- %t@]"
33223322+ %a@]"
33233323 Style.inline_code "with"
33243324- (Style.as_inline_code longident) lid main
33243324+ (Style.as_inline_code longident) lid
33253325+ Includemod_errorprinter.err_msgs explanation
33253326 | With_makes_applicative_functor_ill_typed(lid, path, explanation) ->
33263326- let main = Includemod_errorprinter.err_msgs explanation in
33273327- let footnote = Printtyp.Conflicts.err_msg in
33283328- Location.errorf ~loc ~footnote
33273327+ Location.errorf ~loc ~footnote:Printtyp.Conflicts.err_msg
33293328 "@[<v>\
33303329 @[This %a constraint on %a makes the applicative functor @ \
33313330 type %a ill-typed in the constrained signature:@]@ \
33323332- %t@]"
33313331+ %a@]"
33333332 Style.inline_code "with"
33343333 (Style.as_inline_code longident) lid
33353334 Style.inline_code (Path.name path)
33363336- main
33353335+ Includemod_errorprinter.err_msgs explanation
33373336 | With_changes_module_alias(lid, id, path) ->
33383337 Location.errorf ~loc
33393338 "@[<v>\
···33533352 [ 12; 7; 3 ]
33543353 in
33553354 let pp_constraint ppf () =
33563356- Format.fprintf ppf "%s := %a"
33553355+ fprintf ppf "%s := %a"
33573356 (Path.name p) Printtyp.modtype mty
33583357 in
33593358 Location.errorf ~loc
···35083507 Misc.print_see_manual manual_ref
3509350835103509let report_error env ~loc err =
35113511- Printtyp.wrap_printing_env_error env
35103510+ Printtyp.wrap_printing_env ~error:true env
35123511 (fun () -> report_error env ~loc err)
3513351235143513let () =
+11-14
typing/typetexp.ml
···857857858858(* Error report *)
859859860860-open Format
860860+open Format_doc
861861open Printtyp
862862module Style = Misc.Style
863863-let pp_tag ppf t = Format.fprintf ppf "`%s" t
864864-863863+let pp_tag ppf t = fprintf ppf "`%s" t
864864+let pp_type ppf ty = Style.as_inline_code !Oprint.out_type ppf ty
865865866866let report_error env ppf = function
867867 | Unbound_type_variable (name, in_scope_names) ->
···881881 (Style.as_inline_code longident) lid expected provided
882882 | Bound_type_variable name ->
883883 fprintf ppf "Already bound type parameter %a"
884884- (Style.as_inline_code Pprintast.tyvar) name
884884+ (Style.as_inline_code Pprintast.Doc.tyvar) name
885885 | Recursive_type ->
886886 fprintf ppf "This type is recursive"
887887 | Type_mismatch trace ->
888888+ let msg = Format_doc.Core.msg in
888889 Printtyp.report_unification_error ppf Env.empty trace
889889- (function ppf ->
890890- fprintf ppf "This type")
891891- (function ppf ->
892892- fprintf ppf "should be an instance of type")
890890+ (msg "This type")
891891+ (msg "should be an instance of type")
893892 | Alias_type_mismatch trace ->
893893+ let msg = Format_doc.Core.msg in
894894 Printtyp.report_unification_error ppf Env.empty trace
895895- (function ppf ->
896896- fprintf ppf "This alias is bound to type")
897897- (function ppf ->
898898- fprintf ppf "but is used as an instance of type")
895895+ (msg "This alias is bound to type")
896896+ (msg "but is used as an instance of type")
899897 | Present_has_conjunction l ->
900898 fprintf ppf "The present constructor %a has a conjunctive type"
901899 Style.inline_code l
···912910 Style.inline_code ">"
913911 (Style.as_inline_code pp_tag) l
914912 | Constructor_mismatch (ty, ty') ->
915915- let pp_type ppf ty = Style.as_inline_code !Oprint.out_type ppf ty in
916913 wrap_printing_env ~error:true env (fun () ->
917914 Printtyp.prepare_for_printing [ty; ty'];
918915 fprintf ppf "@[<hov>%s %a@ %s@ %a@]"
···942939 | Cannot_quantify (name, v) ->
943940 fprintf ppf
944941 "@[<hov>The universal type variable %a cannot be generalized:@ "
945945- (Style.as_inline_code Pprintast.tyvar) name;
942942+ (Style.as_inline_code Pprintast.Doc.tyvar) name;
946943 if Btype.is_Tvar v then
947944 fprintf ppf "it escapes its scope"
948945 else if Btype.is_Tunivar v then
+1-1
typing/typetexp.mli
···95959696exception Error of Location.t * Env.t * error
97979898-val report_error: Env.t -> Format.formatter -> error -> unit
9898+val report_error: Env.t -> error Format_doc.printer
9999100100(* Support for first-class modules. *)
101101val transl_modtype_longident: (* from Typemod *)
+4-3
utils/diffing.ml
···4242 | Modification -> Misc.Style.[ FG Magenta; Bold]
43434444let prefix ppf (pos, p) =
4545+ let open Format_doc in
4546 let sty = style p in
4646- Format.pp_open_stag ppf (Misc.Style.Style sty);
4747- Format.fprintf ppf "%i. " pos;
4848- Format.pp_close_stag ppf ()
4747+ pp_open_stag ppf (Misc.Style.Style sty);
4848+ fprintf ppf "%i. " pos;
4949+ pp_close_stag ppf ()
495050515152let (let*) = Option.bind
···3737 in
3838 let style k ppf inner =
3939 let sty = Diffing.style k in
4040- Format.pp_open_stag ppf (Misc.Style.Style sty);
4141- Format.kfprintf (fun ppf -> Format.pp_close_stag ppf () ) ppf inner
4040+ Format_doc.pp_open_stag ppf (Misc.Style.Style sty);
4141+ Format_doc.kfprintf (fun ppf -> Format_doc.pp_close_stag ppf () ) ppf inner
4242 in
4343 match x with
4444 | Change (Name {pos; _ } | Type {pos; _})
···53535454(** To detect [move] and [swaps], we are using the fact that
5555 there are 2-cycles in the graph of name renaming.
5656- - [Change (x,y,_) is then an edge from
5656+ - [Change (x,y,_)] is then an edge from
5757 [key_left x] to [key_right y].
5858 - [Insert x] is an edge between the special node epsilon and
5959 [key_left x]
+1-1
utils/diffing_with_keys.mli
···4646 | Insert of {pos:int; insert:'r}
4747 | Delete of {pos:int; delete:'l}
48484949-val prefix: Format.formatter -> ('l,'r,'diff) change -> unit
4949+val prefix: ('l,'r,'diff) change Format_doc.printer
50505151module Define(D:Diffing.Defs with type eq := unit): sig
5252
···5757 - Some implementation appear
5858 before their dependencies *)
59596060-open Format
61606262-val report_error
6363- : print_filename:(formatter -> string -> unit)
6464- -> formatter -> error -> unit
6161+val report_error :
6262+ print_filename:string Format_doc.printer -> error Format_doc.printer
+14-33
utils/misc.ml
···651651652652653653 let as_inline_code printer ppf x =
654654- Format.pp_open_stag ppf (Format.String_tag "inline_code");
654654+ let open Format_doc in
655655+ pp_open_stag ppf (Format.String_tag "inline_code");
655656 printer ppf x;
656656- Format.pp_close_stag ppf ()
657657+ pp_close_stag ppf ()
657658658658- let inline_code ppf s = as_inline_code Format.pp_print_string ppf s
659659+ let inline_code ppf s = as_inline_code Format_doc.pp_print_string ppf s
659660660661 (* either prints the tag of [s] or delegates to [or_else] *)
661662 let mark_open_tag ~or_else s =
···769770 let env = List.sort_uniq (fun s1 s2 -> String.compare s2 s1) env in
770771 fst (List.fold_left (compare name) ([], max_int) env)
771772773773+772774let did_you_mean ppf get_choices =
775775+ let open Format_doc in
773776 (* flush now to get the error report early, in the (unheard of) case
774777 where the search in the get_choices function would take a bit of
775778 time; in the worst case, the user has seen the error, she can
776779 interrupt the process before the spell-checking terminates. *)
777777- Format.fprintf ppf "@?";
780780+ fprintf ppf "@?";
778781 match get_choices () with
779782 | [] -> ()
780783 | choices ->
781784 let rest, last = split_last choices in
782782- let comma ppf () = Format.fprintf ppf ", " in
783783- Format.fprintf ppf "@\n@{<hint>Hint@}: Did you mean %a%s%a?@?"
784784- (Format.pp_print_list ~pp_sep:comma Style.inline_code) rest
785785+ fprintf ppf "@\n@[@{<hint>Hint@}: Did you mean %a%s%a?@]"
786786+ (pp_print_list ~pp_sep:comma Style.inline_code) rest
785787 (if rest = [] then "" else " or ")
786788 Style.inline_code last
787789···832834 let stop = loop 0 0 in
833835 Bytes.sub_string dst 0 stop
834836835835-let pp_two_columns ?(sep = "|") ?max_lines ppf (lines: (string * string) list) =
836836- let left_column_size =
837837- List.fold_left (fun acc (s, _) -> Int.max acc (String.length s)) 0 lines in
838838- let lines_nb = List.length lines in
839839- let ellipsed_first, ellipsed_last =
840840- match max_lines with
841841- | Some max_lines when lines_nb > max_lines ->
842842- let printed_lines = max_lines - 1 in (* the ellipsis uses one line *)
843843- let lines_before = printed_lines / 2 + printed_lines mod 2 in
844844- let lines_after = printed_lines / 2 in
845845- (lines_before, lines_nb - lines_after - 1)
846846- | _ -> (-1, -1)
847847- in
848848- Format.fprintf ppf "@[<v>";
849849- List.iteri (fun k (line_l, line_r) ->
850850- if k = ellipsed_first then Format.fprintf ppf "...@,";
851851- if ellipsed_first <= k && k <= ellipsed_last then ()
852852- else Format.fprintf ppf "%*s %s %s@," left_column_size line_l sep line_r
853853- ) lines;
854854- Format.fprintf ppf "@]"
855855-856837(* showing configuration and configuration variables *)
857838let show_config_and_exit () =
858839 Config.print_config stdout;
···909890 []
910891 end
911892912912-let print_if ppf flag printer arg =
913913- if !flag then Format.fprintf ppf "%a@." printer arg;
914914- arg
915915-916893let print_see_manual ppf manual_section =
917917- let open Format in
894894+ let open Format_doc in
918895 fprintf ppf "(see manual section %a)"
919896 (pp_print_list ~pp_sep:(fun f () -> pp_print_char f '.') pp_print_int)
920897 manual_section
898898+899899+let print_if ppf flag printer arg =
900900+ if !flag then Format.fprintf ppf "%a@." printer arg;
901901+ arg
921902922903923904type filepath = string
+5-30
utils/misc.mli
···445445 list of suggestions taken from [env], that are close enough to
446446 [name] that it may be a typo for one of them. *)
447447448448-val did_you_mean : Format.formatter -> (unit -> string list) -> unit
448448+val did_you_mean :
449449+ Format_doc.formatter -> (unit -> string list) -> unit
449450(** [did_you_mean ppf get_choices] hints that the user may have meant
450451 one of the option returned by calling [get_choices]. It does nothing
451452 if the returned list is empty.
···505506 inline_code: tag_style;
506507 }
507508508508- val as_inline_code: (Format.formatter -> 'a -> unit as 'printer) -> 'printer
509509- val inline_code: Format.formatter -> string -> unit
509509+ val as_inline_code: 'a Format_doc.printer -> 'a Format_doc.printer
510510+ val inline_code: string Format_doc.printer
510511511512 val default_styles: styles
512513 val get_styles: unit -> styles
···536537 Format.formatter -> bool ref -> (Format.formatter -> 'a -> unit) -> 'a -> 'a
537538(** [print_if ppf flag fmt x] prints [x] with [fmt] on [ppf] if [b] is true. *)
538539539539-val pp_two_columns :
540540- ?sep:string -> ?max_lines:int ->
541541- Format.formatter -> (string * string) list -> unit
542542-(** [pp_two_columns ?sep ?max_lines ppf l] prints the lines in [l] as two
543543- columns separated by [sep] ("|" by default). [max_lines] can be used to
544544- indicate a maximum number of lines to print -- an ellipsis gets inserted at
545545- the middle if the input has too many lines.
546546-547547- Example:
548548-549549- {v pp_two_columns ~max_lines:3 Format.std_formatter [
550550- "abc", "hello";
551551- "def", "zzz";
552552- "a" , "bllbl";
553553- "bb" , "dddddd";
554554- ] v}
555555-556556- prints
557557-558558- {v
559559- abc | hello
560560- ...
561561- bb | dddddd
562562- v}
563563-*)
564564-565565-val print_see_manual : Format.formatter -> int list -> unit
540540+val print_see_manual : int list Format_doc.printer
566541(** See manual section *)
567542568543(** {1 Displaying configuration variables} *)
+6-4
utils/warnings.ml
···5252 | Implicit_public_methods of string list (* 15 *)
5353 | Unerasable_optional_argument (* 16 *)
5454 | Undeclared_virtual_method of string (* 17 *)
5555- | Not_principal of string (* 18 *)
5555+ | Not_principal of Format_doc.t (* 18 *)
5656 | Non_principal_labels of string (* 19 *)
5757 | Ignored_extra_argument (* 20 *)
5858 | Nonreturning_statement (* 21 *)
···926926 ^ String.concat " " l ^ "."
927927 | Unerasable_optional_argument -> "this optional argument cannot be erased."
928928 | Undeclared_virtual_method m -> "the virtual method "^m^" is not declared."
929929- | Not_principal s -> s^" is not principal."
929929+ | Not_principal msg ->
930930+ Format_doc.asprintf "%a is not principal."
931931+ Format_doc.pp_doc msg
930932 | Non_principal_labels s -> s^" without principality."
931933 | Ignored_extra_argument -> "this argument will not be used by the function."
932934 | Nonreturning_statement ->
···10401042 "Code should not depend on the actual values of\n\
10411043 this constructor's arguments. They are only for information\n\
10421044 and may change in future versions. %a"
10431043- Misc.print_see_manual ref_manual
10451045+ (Format_doc.compat Misc.print_see_manual) ref_manual
10441046 | Unreachable_case ->
10451047 "this match case is unreachable.\n\
10461048 Consider replacing it with a refutation case '<pat> -> .'"
···10711073 %s.\n\
10721074 Only the first match will be used to evaluate the guard expression.\n\
10731075 %a"
10741074- vars_explanation Misc.print_see_manual ref_manual
10761076+ vars_explanation (Format_doc.compat Misc.print_see_manual) ref_manual
10751077 | No_cmx_file name ->
10761078 Printf.sprintf
10771079 "no cmx file was found in path for module %s, \
+1-1
utils/warnings.mli
···5757 | Implicit_public_methods of string list (* 15 *)
5858 | Unerasable_optional_argument (* 16 *)
5959 | Undeclared_virtual_method of string (* 17 *)
6060- | Not_principal of string (* 18 *)
6060+ | Not_principal of Format_doc.t (* 18 *)
6161 | Non_principal_labels of string (* 19 *)
6262 | Ignored_extra_argument (* 20 *)
6363 | Nonreturning_statement (* 21 *)