goblint / analyzer

Static analysis framework for C
https://goblint.in.tum.de
MIT License
164 stars 72 forks source link

use ppx to reduce boilerplate code #31

Open vogler opened 8 years ago

vogler commented 8 years ago

Use type-driven code generation to get rid of boilerplate (see ppx_deriving):

sim642 commented 3 years ago

At some point I found ppx_yojson, which attempts to simplify manual creation of Yojson values, e.g. by converting OCaml record-like syntax to a JSON object. It's not for deriving anything but just avoids having to construct Yojson values directly using its constructors.

This might be useful for manual implementations of to_yojson, which @keremc is adding more of. Although I think all those manual implementations are simple enough (e.g. a single string) that this isn't really worth it, but I'm still mentioning it here so I can close the tab...

sim642 commented 2 years ago

I happened upon ppx_type_directed_value, which Jane Street just has, but I've never heard of anyone using. Its idea being to make custom deriving plugins easier to define by not having to write a ppx deriver from scratch but just define the behavior for product and sum types and have it automagically work for all tuples, records, etc.

It sounds like a nice way to define our own lattice derivers, but it adds the Jane Street Base dependency and has notable performance implications:

The usage of this PPX does incur a runtime cost proportional to the size of the type (e.g. number of fields/constructors/elements in a record/variant/tuple). In particular, if the type-directed value is a function type, there will be a runtime cost on every invocation of the function.

In their benchmarking example they reimplement equality deriving, which via this ppx is ~4× slower than a direct equality deriver. So I'm a bit skeptical if it'd be fast enough to replace our currently hand-written lattice definitions.