Skip to content

Migrate from CIL's Pretty to OCaml's Format #213

@sim642

Description

@sim642

In #210 it came up multiple times that OCaml's standard Format module could replace Pretty from CIL with additional benefits:

  1. It's maintained in OCaml's standard library while Pretty isn't properly maintained (maybe we should do this migration even in our CIL fork eventually).
  2. It has much more features for producing pretty output.
  3. It's supposed to be faster by not constructing Pretty.doc structures but writing to a formatter directly (a la how Printable.printXml currently works).
  4. It's supposed to be faster by using GADTs for internal implementation instead of Obj (Possibly excessive functions in Printable.S #210 (comment)).
  5. ppx_deriving.std has deriving show that also derives a pretty-printer in addition to a simple show (Possibly excessive functions in Printable.S #210 (comment)).
  6. It allows custom semantic tags, e.g. for colors, and their behavior can depend on where the output is going (to the terminal or to a string).

TODO

  • Replace Printable.pretty with val pp: Format.formatter -> t -> unit. This is the de facto standard naming for these pretty printer and deriving show also derives this signature.
  • Rewrite every implementation of pretty as pp.
  • Rewrite every Pretty.printf with Format.printf by using pp instead of pretty.
  • Rewrite tracing system to use Format instead of Pretty.
  • Rewrite every trace by using pp instead of pretty.
  • Implement pp for CIL types, e.g. pp_exp to replace d_exp. CIL has a lot of Pretty-based code to pretty-print everything (including entire programs). We don't need all of it though unless we also decide to migrate CIL itself.

Metadata

Metadata

Assignees

Labels

cleanupRefactoring, clean-up

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions