Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006017OCamlstandard librarypublic2013-05-18 02:392017-02-16 15:14
Assigned Togasche 
PlatformOSOS Version
Product Version4.00.1 
Target Version4.02.0+devFixed in Version4.02.0+dev 
Summary0006017: A new format implementation based on GADTs
DescriptionI wrote a new implementation of formats unsing GADTs.

It contains modifications of Printf, Format and Scanf standard library
modules, and OCaml typer adaptations (principally in typing/

In this new implementation, formats are compiled into GADTs trees by
the compiler and are "evaluated" by the printing and scanning functions.
The main advantages are :
 * No longer use of Obj.magic in, and
 * Better performances.
 * Stronger static verifications of format validity (flag compatibilities, ...).
 * Factorisation of format parsing in a single code (for all the stdlib
   and the OCaml compiler!) to ensure compatibility.

This new version is "mostly compatible" with the old-one. Differencies are :
 * Some inconsistent formats are now statically rejected, like
   "%1.1s", "%#s", "%0c" (I had to slightly adapt the testsuite,
   principally to comment absud tests which no longer compile, so, obviously,
   I did not remove any test which still compile).
 * Some bug fixes :
   * The semantic of (printf "%{...%}") (from comments of the testsuite).
   * The semantic of (scanf "%[^...]@X").
   * The '@%' escape syntax, like in (Format.printf "@%d%s" 42 "hello").
   * The managment of nested "%{...%}" and "%(...%)".
   * Buffer overflows dues to too big padding (or precision).
   * ...
 * To obtain compatibility of Printf and Format formats, some '@' usages
   with an "invalid Format-like syntax" but a "valid Printf-like syntax"
   are now accepted by Format printing functions and literally printed.
   It is a small disadvantage because it is slightly less convenient to
   learn Format "formatting info" syntax by practice, sorry.

Since the OCaml standard library and the OCaml compilers use formats, the
bootstrap is a bit complicated.

I attach two patches (ocaml-4.00.1_new-formats_patch-{1,2}.diff) and
instructions to apply them into "howto-apply-new-formats-patches.txt".
This .txt file can be used (with a slight adaptation from your config.)
as an installation shell-script.

Please do not hesitate to send me any comments or questions about this code.

BenoƮt Vaugon.
Attached Filestxt file icon howto-apply-new-formats-patches.txt [^] (488 bytes) 2013-05-18 02:39 [Show Content]
diff file icon ocaml-4.00.1_new-formats_patch-1.diff [^] (188,380 bytes) 2013-05-18 02:40 [Show Content]
diff file icon ocaml-4.00.1_new-formats_patch-2.diff [^] (188,988 bytes) 2013-05-18 02:40 [Show Content]
? file icon [^] (6,236 bytes) 2013-05-24 15:46 [Show Content]
txt file icon format_gadt_distinguish_N_L.txt [^] (5,264 bytes) 2013-05-26 15:50 [Show Content]
diff file icon fix-incompatible-formats-raising-time-patch.diff [^] (11,436 bytes) 2013-05-26 16:30 [Show Content]
txt file icon howto-apply-new-formats-NOPAIR-patches.txt [^] (518 bytes) 2013-07-22 23:56 [Show Content]
diff file icon ocaml-4.00.1_new-formats_NOPAIR_patch-1.diff [^] (196,816 bytes) 2013-07-22 23:56 [Show Content]
diff file icon ocaml-4.00.1_new-formats_NOPAIR_patch-2.diff [^] (188,500 bytes) 2013-07-22 23:57 [Show Content]
txt file icon howto-apply-new-formats-PAIR-patches.txt [^] (514 bytes) 2013-07-22 23:57 [Show Content]
diff file icon ocaml-4.00.1_new-formats_PAIR_patch-1.diff [^] (176,039 bytes) 2013-07-22 23:57 [Show Content]
diff file icon ocaml-4.00.1_new-formats_PAIR_patch-2.diff [^] (187,914 bytes) 2013-07-22 23:57 [Show Content]