-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Original bug ID: 6017
Reporter: bvaugon
Assigned to: @gasche
Status: closed (set by @xavierleroy on 2017-02-16T14:14:38Z)
Resolution: fixed
Priority: high
Severity: feature
Version: 4.00.1
Target version: 4.02.0+dev
Fixed in version: 4.02.0+dev
Category: standard library
Tags: patch
Related to: #5949 #6286 #6297 #7034
Monitored by: ibnfirnas @gasche @lpw25 mcclurmc @diml "Pascal Cuoq" bobot @chambart @jmeber @hcarty @yakobowski @alainfrisch
Bug description
I 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/typecore.ml).
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 printf.ml, scanf.ml and format.ml.
- 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.
File attachments
- fix-incompatible-formats-raising-time-patch.diff
- format_gadt_distinguish_N_L.txt
- howto-apply-new-formats-NOPAIR-patches.txt
- howto-apply-new-formats-PAIR-patches.txt
- howto-apply-new-formats-patches.txt
- ocaml-4.00.1_new-formats_NOPAIR_patch-1.diff
- ocaml-4.00.1_new-formats_NOPAIR_patch-2.diff
- ocaml-4.00.1_new-formats_PAIR_fix-expected-type.diff
- ocaml-4.00.1_new-formats_PAIR_patch-1.diff
- ocaml-4.00.1_new-formats_PAIR_patch-2.diff
- ocaml-4.00.1_new-formats_patch-1.diff
- ocaml-4.00.1_new-formats_patch-2.diff
- special_case_for_small_arities.ml