facebook / pyre-check

Performant type-checking for python.
https://pyre-check.org/
MIT License
6.79k stars 432 forks source link

[pysa][MLH] Add a show to Registry #869

Open arthaud opened 3 months ago

arthaud commented 3 months ago

When debugging, it can be useful to print the content of a Registry: https://github.com/facebook/pyre-check/blob/main/source/interprocedural/fixpointAnalysis.ml#L143

Unfortunately, it does not currently implement pp or show. Let's add those.

Note that we can use something like this to pretty print a map-like structure:

let pp_map pp_value formatter map =
    let pp_pairs pp_value formatter pairs =
      let pp_pair formatter key value =
        Format.fprintf formatter "@,%s -> [%a]" key pp_value value
      in
      iter (pp_pair formatter) pairs
    in
    Format.fprintf formatter "{@[<v 2>%a@]@,}" (pp_pairs pp_value) map

let show ~pp_value map = Format.asprintf "%a" (pp_map pp_value) map

This is tracked internally by T123569270.